Class: Query::Result::QihuMobile

Inherits:
Object
  • Object
show all
Includes:
Query::Result
Defined in:
lib/query/result/qihu_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

#htmlObject



6
7
8
# File 'lib/query/result/qihu_mobile.rb', line 6

def html
  @page.to_html
end

#next_urlObject



10
11
12
# File 'lib/query/result/qihu_mobile.rb', line 10

def next_url
 "#{@baseuri.to_s}&pn=#{@pagenumber+1}"
end


45
46
47
# File 'lib/query/result/qihu_mobile.rb', line 45

def related_keywords
  @related_keywords ||= @page.search("//div[@class='related-search-b']//a").map{|relwd| relwd.text.gsub(/ |\n|\t/,"")}
end

#seo_ranksObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/query/result/qihu_mobile.rb', line 14

def seo_ranks
	@page.css('div.g-card').map.with_index do |seo_div,index|
		begin
			cite = seo_div.at('.//*[@class="res-show-url"]/text()')
			a = seo_div.at_css('a')	
			if cite
				cite = cite.to_s.gsub(/ |-/,'') 
			else   
				url = seo_div.at('.//a[contains(@href,"u=")]') 
			  if url
 		cite = URI.decode(CGI.parse(URI(URI.encode(url['href'])).query)['u'][0])
 		cite = URI(URI.encode(cite)).host
 	else
 		cite = "m.haosou.com"
 	end
    	end
    	title = seo_div.at_css('h3') || a        	
    	{	
    		:is_vr => seo_div['class']=="g-card r-og-card" ? false : true,
      	:rank  => index + 1 + (@pagenumber-1)*10,
      	:href  => a['href'],
      	:text  => title.text.gsub(/ |\n|\s/,""),
      	:host  => cite
    	}
    rescue Exception => e
    	warn "Error in parse_seo method : " + e.message
    	{}
    end
  end
end