class Query::Result::SMobile
Public Instance Methods
ads_bottom()
click to toggle source
# File lib/query/result/sm_mobile.rb, line 19 def ads_bottom selector = "//div[@id='results']/div[@class='result card'][1]/following-sibling::div[@class='ali_row result card']" @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_right()
click to toggle source
# File lib/query/result/sm_mobile.rb, line 35 def ads_right [] end
ads_top()
click to toggle source
# File lib/query/result/sm_mobile.rb, line 12 def ads_top selector = "//div[@id='results']/div[@class='result card'][1]/preceding-sibling::div[@class='ali_row result card']" @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
count()
click to toggle source
# File lib/query/result/sm_mobile.rb, line 43 def count end
html()
click to toggle source
# File lib/query/result/sm_mobile.rb, line 31 def html @page.to_html end
next_url()
click to toggle source
# File lib/query/result/sm_mobile.rb, line 39 def next_url "#{@baseuri.to_s}&page=#{@pagenumber+1}" end
seo_ranks()
click to toggle source
# File lib/query/result/sm_mobile.rb, line 6 def seo_ranks @seo_ranks ||= @page.search("//div[@id='results']/div[@class!='ali_row result card']").map.with_index do |seo_div,index| parse_seo(seo_div).merge({:rank => (index + 1) + (@pagenumber -1) * 10}) end end
Private Instance Methods
parse_ad(ad_div)
click to toggle source
# File lib/query/result/sm_mobile.rb, line 48 def parse_ad(ad_div) begin title_link = ad_div.at_css('a') title = title_link.search('./text()|./em|./span') url = ad_div.search('.//div[@class="host"]/text()').text url = "http://#{url}" if !url[/http:/] { :text => title.text.gsub(/\n|\s/,''), :href => title_link['href'], :host => URI(URI.encode(url.gsub(/ |\n|\t|\s/,""))).host } rescue Exception => e warn "Error in parse_ads method : " + e.message {} end end
parse_seo(seo_div)
click to toggle source
# File lib/query/result/sm_mobile.rb, line 65 def parse_seo(seo_div) begin title_link = seo_div.at('.//a[contains(@href,"http://")]') href = title_link['href'] if seo_div['class']=="result card" is_vr = false url = seo_div.search('.//div[@class="host"]/span/text()[matches(.,"\w+.\w+")]', XpathFunctions.new)[0] || href else is_vr, url = true, href end url = "http://#{url}" if !url[/http:/] { :is_vr => is_vr, :text => title_link.text.gsub(/\n|\s/,'')[0..30], :href => href, :host => URI(URI.encode(url.gsub(/ |\n|\t|\s/,""))).host # remove   and whitespace } rescue Exception => e warn "Error in parse_seo method : " + e.message {} end end