ruby cgi

L

lloyd

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.
 
A

anne001

can someone suggest a better implementation of this cgi ruby tool so
also, I wanted to know of a way to easily pass the value back into the
original page with the form.

Better in what sense? Your question is how to return results to the
first page?

I am new to cgi and ruby, so I may not be able to help.

In the example I worked on, I wrote a code which presents a tool, the
tool searches for the
information on the web, and I create a new web page to present the
results.

It seems to me that if your first page is generated by cgi code, you
can regenerate it
with the results of your search included?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,206
Messages
2,571,069
Members
47,677
Latest member
MoisesKoeh

Latest Threads

Top