| Computers Forum Index » Computer Languages (Ruby) » ruby cgi |
|
Page 1 of 1 |
|
| Author |
Message |
| lloyd@binaryten.com |
Posted: Sat Jun 03, 2006 8:05 pm |
|
|
|
Guest
|
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 |
|
|
| Back to top |
|
|
|
| Tim Hammerquist |
Posted: Sat Jun 03, 2006 10:11 pm |
|
|
|
Guest
|
lloyd@binaryten.com <lloyd@binaryten.com> wrote:
Quote: 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 |
|
|
| Back to top |
|
|
|
| lloyd@binaryten.com |
Posted: Sun Jun 04, 2006 5:33 pm |
|
|
|
Guest
|
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:
Quote: 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 |
|
|
| Back to top |
|
|
|
| anne001 |
Posted: Thu Jun 08, 2006 11:23 am |
|
|
|
Guest
|
Quote: 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...
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? |
|
|
| Back to top |
|
|
|
|