Created
March 16, 2010 15:02
-
-
Save lackac/334059 to your computer and use it in GitHub Desktop.
4. gyakorlat – Googler feladat megoldás
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'nokogiri' | |
require 'uri' | |
require 'open-uri' | |
print "Mi a neved? " | |
query = gets.chomp | |
uri = "http://www.google.com/search?q=#{URI.encode(%{"#{query}"})}" | |
# puts uri | |
doc = Nokogiri::HTML(open(uri)) | |
# puts doc.to_xhtml(:indent => 2) | |
# File.open("page.html", "w") {|f| doc.write_xhtml_to(f, :indent => 2)} | |
doc.css(".g").each do |hit| | |
link = hit.at_css("h3 a") | |
if summary = hit.at_css(".s") and summary.child.name != "table" | |
puts link.content | |
puts link['href'] | |
summary.css("div", "cite", ".gl").remove | |
puts summary.content | |
puts | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment