Class: Query::Engine::Qihu
- Inherits:
-
Object
- Object
- Query::Engine::Qihu
- Includes:
- Query::Engine
- Defined in:
- lib/query/engine/qihu.rb
Constant Summary collapse
- Host =
'www.so.com'
- Options =
{:headers => headers}
Instance Attribute Summary
Attributes included from Query::Engine
Class Method Summary collapse
Instance Method Summary collapse
-
#query(wd) ⇒ Object
基本查询, 相当于在搜索框直接数据关键词查询.
Methods included from Query::Engine
Class Method Details
.related_keywords(wd) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/query/engine/qihu.rb', line 21 def self.(wd) url = "http://rs.so.com/?callback=Search.relate.render&encodein=utf-8&encodeout=utf-8&q="+URI.encode(wd) # uri = URI.join("http://#{Host}/",URI.encode('s?q='+wd)).to_s page = HTTParty.get(url) json_str = page.body json_str = json_str.split("(")[1] return nil if json_str.nil? json_str = json_str.delete(');').strip parsed_json = JSON.parse(json_str) # each # parsed_json.map { |q| p q['q']} @related_keywords = parsed_json.map { |q| q['q'] } # @related_keywords ||= @page.search("//div[@id=\"rs\"]//tr//a").map{|keyword| keyword.text} end |
Instance Method Details
#query(wd) ⇒ Object
基本查询, 相当于在搜索框直接数据关键词查询
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/query/engine/qihu.rb', line 11 def query(wd) #用原始路径请求 uri = URI.join("http://#{Host}/",URI.encode('s?q='+wd)).to_s page = HTTParty.get(uri,Options) #如果请求地址被跳转,重新获取当前页的URI,可避免翻页错误 uri = URI.join("http://#{Host}/",page.request.path).to_s r = Query::Result::Qihu.new(page) r.baseuri = uri r end |