Created
December 14, 2010 16:49
-
-
Save mstrauss/740678 to your computer and use it in GitHub Desktop.
Scrape Google Links (Files names 01.html .. 10.html)
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
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'nokogiri' # for XML parsing | |
# these are our (manually downloaded) input files | |
files = (1..10).collect { |i| "%02d.html" % i } | |
# thee results (links) go here | |
outfile = File.open("output.txt", "w") | |
files.each do |filename| | |
doc = Nokogiri::HTML( File.read(filename) ) | |
doc.css('h3.r a.l').each do |link| | |
outfile.puts link['href'] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment