Class: QihooResult
- Inherits:
-
SearchResult
- Object
- SearchResult
- QihooResult
- Defined in:
- lib/baidu.rb
Constant Summary collapse
- Host =
'www.so.com'
Instance Method Summary collapse
-
#has_result? ⇒ Boolean
有结果.
-
#next ⇒ Object
下一页.
-
#ranks ⇒ Object
返回所有当前页的排名结果.
Methods inherited from SearchResult
#initialize, #rank, #ranks_for
Constructor Details
This class inherits a constructor from SearchResult
Instance Method Details
#has_result? ⇒ Boolean
有结果
99 100 101 |
# File 'lib/baidu.rb', line 99 def has_result? !@body.xpath('//div[@id="main"]/h3').text().include?'没有找到该URL' end |
#next ⇒ Object
下一页
88 89 90 91 92 93 94 95 96 97 |
# File 'lib/baidu.rb', line 88 def next next_href = @body.xpath('//a[@id="snext"]') return false if next_href.empty? next_href = next_href.first['href'] next_href = URI.join(@baseuri,next_href).to_s # next_href = URI.join("http://#{@host}",next_href).to_s next_body = HTTParty.get(next_href).body return QihooResult.new(next_body,next_href,@pagenumber+1) #@page = MbaiduResult.new(Mechanize.new.click(@page.link_with(:text=>/下一页/))) unless @page.link_with(:text=>/下一页/).nil? end |
#ranks ⇒ Object
返回所有当前页的排名结果
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/baidu.rb', line 70 def ranks return @ranks unless @ranks.nil? @ranks = Hash.new id = (@pagenumber - 1) * 10 @body.xpath('//li[@class="res-list"]').each do |li| a = li.search("h3/a").first url = li.search("cite") next if a['data-pos'].nil? id += 1 text = a.text.strip href = a['href'] url = url.first.text host = Addressable::URI.parse(URI.encode("http://#{url}")).host @ranks[id.to_s] = {'href'=>"http://so.com#{href}",'text'=>text,'host'=>host} end @ranks end |