Class: Query::Result::BaiduMobile

Inherits:
Object
  • Object
show all
Includes:
Query::Result
Defined in:
lib/query/result/baidu_mobile.rb

Instance Attribute Summary

Attributes included from Query::Result

#baseuri, #options, #pagenumber, #perpage

Instance Method Summary collapse

Methods included from Query::Result

#initialize, #next, #rank, #raw_ranks

Instance Method Details

#ads_bottomObject



20
21
22
23
24
25
# File 'lib/query/result/baidu_mobile.rb', line 20

def ads_bottom
  selector = "//*[@class='result']/following-sibling::div[not (contains(@class,'result'))]/div/div/a[not (contains(@href,'http://baozhang.baidu.com/guarantee'))]/.."
  @ads_bottom ||= @page.search(selector).map.with_index do |ad_div,index|
    parse_ad(ad_div).merge({:rank => (index + 1) + (@pagenumber -1) * 10})
  end
end

#ads_rightObject



36
37
38
# File 'lib/query/result/baidu_mobile.rb', line 36

def ads_right
  []
end

#ads_topObject



13
14
15
16
17
18
# File 'lib/query/result/baidu_mobile.rb', line 13

def ads_top
  selector = "//*[@class='result']/preceding-sibling::div[not (contains(@class,'result'))]/div/div/a[not (contains(@href,'http://baozhang.baidu.com/guarantee'))]/.."
  @ads_top ||= @page.search(selector).map.with_index do |ad_div,index|
    parse_ad(ad_div).merge({:rank => (index + 1) + (@pagenumber -1) * 10})
  end
end

#countObject



46
47
48
# File 'lib/query/result/baidu_mobile.rb', line 46

def count

end

#htmlObject



32
33
34
# File 'lib/query/result/baidu_mobile.rb', line 32

def html
  @page.to_html
end

#next_urlObject



40
41
42
43
44
# File 'lib/query/result/baidu_mobile.rb', line 40

def next_url
	next_bn = @page.search("//div[@id='pagenav']/a").first
  url = next_bn.nil? ? "/s?#{@baseuri.query}&pn=#{@pagenumber*10}" : next_bn['href']
  url
end

酒店预订 酒店英文 酒店团购 酒店管理 酒店招聘 快捷酒店 如家快捷酒店 五星级酒店



28
29
30
# File 'lib/query/result/baidu_mobile.rb', line 28

def related_keywords
  @related_keywords ||= @page.search("//div[@id='relativewords']/div[@class='rw-list']/a").map { |a| a.text }
end

#seo_ranksObject



6
7
8
9
10
11
# File 'lib/query/result/baidu_mobile.rb', line 6

def seo_ranks
  s_res =  @page.at("//div[@id='results']")
  @seo_ranks ||= s_res.css("div.result").map.with_index do |seo_div,index|
    parse_seo(seo_div).merge({:rank => (index + 1) + (@pagenumber -1) * 10})
  end
end