Created
November 9, 2012 14:27
-
-
Save thomd/4046000 to your computer and use it in GitHub Desktop.
print URLs of google search results to stdout
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 | |
# | |
# print URLs of google search results to stdout | |
# the name 'xgoogle' is a homage to Peteris Krumins' xgoogle | |
# | |
# dependencies: | |
# gem install nokogiri | |
# | |
# usage: | |
# xgoogle <searchquery> [<number-of-results> [<language>]] | |
# | |
# this may be useful for downloading top 10 javascript pdf files: | |
# xgoogle "javascript filetype:pdf" 10 | xargs wget -qc | |
# | |
require 'open-uri' | |
require 'nokogiri' | |
q = ARGV[0].gsub(/ /, '%20') | |
num = ARGV[1] || '100' | |
hl = ARGV[2] || 'en' | |
serp = Nokogiri::HTML(open("http://www.google.com/search?num=#{num}&hl=#{hl}&q=#{q}", :proxy => "http://your-proxy:8080")) | |
serp.css("li.g h3 a").each do |ser| | |
puts ser['href'].match(/url\?q=(.*)&sa=/)[1] | |
end | |
# vim:ft=ruby |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment