you are quite right. I forgot (oops)... here it is...
#!/usr/bin/ruby
print "Content-type: text/html\r\n\r\n"
require 'net/http'
require 'cgi'
def findpage(url,searchterm,start=1,pagesize=100)
if pagesize < 1
print "<p>Current site position:#{start}</p>"
exit
end
page =
"/search?q=#{searchterm}&hl=en&start=#{start}&num=#{pagesize}"
file = Net::HTTP.start("
www.google.com")
header,text = file.get(page)
text.each do |line|
m = /<a class=l href=\"#{url}/
if m =~ line
pagesize /= 10
findpage(url,searchterm,start,pagesize)
exit
end
end
start += pagesize
if start < 1000
findpage(url,searchterm,start,pagesize)
else
p "the site is not listed in the first 1000"
end
end
formdata = CGI.new
url = "
http://#{formdata['url']}"
searchterm = CGI::escape(formdata['phrase'])
findpage(url,searchterm)
also, I wanted to know of a way to easily pass the value back into the
original page with the form.