Class: Query::Result::Qihu
- Inherits:
-
Object
- Object
- Query::Result::Qihu
- Includes:
- Query::Result
- Defined in:
- lib/query/result/qihu.rb
Instance Attribute Summary
Attributes included from Query::Result
#baseuri, #pagenumber, #perpage
Instance Method Summary collapse
- #ads_bottom ⇒ Object
- #ads_right ⇒ Object
- #ads_top ⇒ Object
-
#blocked? ⇒ Boolean
被封.
-
#blocked_ip ⇒ Object
被封的IP.
- #count ⇒ Object
-
#has_result? ⇒ Boolean
有结果.
-
#next_url ⇒ Object
下一页.
- #related_keywords ⇒ Object
- #seo_ranks ⇒ Object
Methods included from Query::Result
#initialize, #next, #rank, #raw_ranks
Instance Method Details
#ads_bottom ⇒ Object
31 32 33 |
# File 'lib/query/result/qihu.rb', line 31 def ads_bottom [] end |
#ads_right ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/query/result/qihu.rb', line 35 def ads_right @page.search("//ul[@id='rightbox']/li").map.with_index do |li,index| a = li.search('a').first href = li.search("cite").first.text.downcase host = Addressable::URI.parse(URI.encode(href)).host next if a.text.include?'想在360推广您的产品服务吗' { :rank => index + 1, :text => a.text, :href => href, :host => host } end.compact end |
#ads_top ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/query/result/qihu.rb', line 17 def ads_top @page.search("//ul[@id='djbox']/li").map.with_index do |li,index| a = li.search("a").first href = li.search("cite").first.text.downcase { :rank => index + 1, :text => a.text, :href => href, :host => Addressable::URI.parse(URI.encode(href)).host } end end |
#blocked? ⇒ Boolean
被封
67 68 69 |
# File 'lib/query/result/qihu.rb', line 67 def blocked? @page.search('//ul[@id="m-result"]').first.nil? and @page.to_s.include?'您的请求暂时无法响应' end |
#blocked_ip ⇒ Object
被封的IP
71 72 73 |
# File 'lib/query/result/qihu.rb', line 71 def blocked_ip (/(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/.match @page.to_s).to_s end |
#count ⇒ Object
54 55 56 |
# File 'lib/query/result/qihu.rb', line 54 def count @page.search('//span[@class="nums"]').first.text.gsub(/\D/,'').to_i end |
#has_result? ⇒ Boolean
有结果
63 64 65 |
# File 'lib/query/result/qihu.rb', line 63 def has_result? !@page.search('//div[@id="main"]/h3').text().include?'没有找到该URL' end |
#next_url ⇒ Object
下一页
59 60 61 |
# File 'lib/query/result/qihu.rb', line 59 def next_url next_href = @page.xpath('//a[@id="snext"]').first['href'] end |
#related_keywords ⇒ Object
50 51 52 |
# File 'lib/query/result/qihu.rb', line 50 def [] end |
#seo_ranks ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/query/result/qihu.rb', line 5 def seo_ranks @page.search('//ul[@id="m-result"]/li//h3').map.with_index do |h3,index| a = h3.search('a').first { :rank => index + 1, :href => a['href'], :text => a.text.strip, :host => Addressable::URI.parse(a['href']).host } end end |