Permalink
Browse files

Updated the basic google example as well

  • Loading branch information...
1 parent ada5df5 commit a311cd0537c17ba3c265e138b10ffddf476a8fec @FiXato committed Nov 1, 2012
Showing with 7 additions and 6 deletions.
  1. +7 −6 examples/basic/google.rb
View
@@ -14,16 +14,17 @@
# Extremely basic method, grabs the first result returned by Google
# or "No results found" otherwise
def google(query)
- url = "http://www.google.com/search?q=#{CGI.escape(query)}"
- res = Nokogiri::HTML(open(url)).at("h3.r")
+ url = "https://www.google.com/search?q=#{CGI.escape(query)}"
+ res = Nokogiri::HTML(open(url)).at(".s")
- title = res.text
- link = res.at('a')[:href]
- desc = res.at("./following::div").children.first.text
+ title = res.at('cite b').text
+ link = res.at('cite').text
+ desc = res.at('.st').text
+ CGI.unescape_html "#{title} - #{desc} (#{link})".dup.force_encoding('binary')
rescue
"No results found"
else
- CGI.unescape_html "#{title} - #{desc} (#{link})"
+ CGI.unescape_html "#{title} - #{desc} (#{link})".dup.force_encoding('binary')
end
end

0 comments on commit a311cd0

Please sign in to comment.