Class: Query::Result::Sogou
- Inherits:
-
Object
- Object
- Query::Result::Sogou
show all
- Includes:
- Query::Result
- Defined in:
- lib/query/result/sogou.rb
Instance Attribute Summary
#baseuri, #pagenumber, #perpage
Instance Method Summary
collapse
#initialize, #next, #rank, #raw_ranks
Instance Method Details
#ads_bottom ⇒ Object
28
29
30
|
# File 'lib/query/result/sogou.rb', line 28
def ads_bottom
return [] if .size < 2
end
|
#ads_right ⇒ Object
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/query/result/sogou.rb', line 17
def ads_right
@page.css('div#right div#bdfs0').map.with_index do |div,index|
{
:rank => index + 1,
:text => div.css('h3 a').text,
:href => div.css('h3 a')[0]['href'],
:host => Addressable::URI.parse(div.css('div.fb a cite').text).host
}
end
end
|
#ads_top ⇒ Object
5
6
7
8
9
10
11
12
13
14
15
|
# File 'lib/query/result/sogou.rb', line 5
def ads_top
return [] if .empty?
.first.search("li").map.with_index do|li,index|
{
:rank => index + 1,
:text => li.css('h3 a').text,
:href => li.css('h3 a')[0]['href'],
:host => Addressable::URI.parse(li.css('cite')[0].text).host
}
end
end
|
#count ⇒ Object
44
45
46
47
48
49
50
|
# File 'lib/query/result/sogou.rb', line 44
def count
["//div[@class='zhanzhang']//em", "//span[@id='scd_num']"].each do |xpath|
if counter_block = @page.search(xpath).first
return counter_block.text.gsub(/\D/,'').to_i
end
end
end
|
#has_result? ⇒ Boolean
62
63
64
|
# File 'lib/query/result/sogou.rb', line 62
def has_result?
@page.search("div[@class='no-result']").empty?
end
|
#next_url ⇒ Object
56
57
58
59
60
|
# File 'lib/query/result/sogou.rb', line 56
def next_url
next_btn = @page.search("//a[text()='下一页>']")
return false if next_btn.empty?
next_btn.first['href']
end
|
52
53
54
|
# File 'lib/query/result/sogou.rb', line 52
def related_keywords
@related_keywords ||= @page.search("table[@id='hint_container']/td").map{|td|td.first.text}
end
|
#seo_ranks ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/query/result/sogou.rb', line 32
def seo_ranks
@page.search("//div[@class='results']/div/h3").map.with_index do |h3,index|
{
:text => h3.search('a').first.text,
:href => h3.search('a').first['href'],
:host => Addressable::URI.parse(h3.search('a').first['href']).host,
:rank => index + 1
}
end
end
|