lloyd@binaryten.com
6/4/2006 1:34:00 PM
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.
Tim Hammerquist wrote:
> lloyd@binaryten.com <lloyd@binaryten.com> wrote:
> > can someone suggest a better implementation of this cgi ruby tool so
> > that i can return the results to the calling page... its my first
> > venture into cgi... www.binaryten.com/english/webtool
>
> All I see is a webpage. It's difficult to suggest a *better*
> implementation if we can't see an implementation to start with.
>
> Tim Hammerquist