[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

use www mechanize issues

junkone

8/4/2006 5:11:00 PM

HI
I am trying to download text file from cboe.org site. here is what i
have done so far
require 'rubygems'
require 'mechanize'
require 'logger'

agent = WWW::Mechanize.new { |a| a.log = Logger.new("mech.log") }
agent.user_agent_alias = 'Mac Safari'
page =
agent.get("http://www.cboe.com/delayedquote/QuoteTableDownload....)
search_form = page.forms.name("QuoteTableDownload").first
search_form.fields.name("ucQuoteTableDownloadCtl:txtTicker").value =
"yhoo"
link=search_form.fields.name("ucQuoteTableDownloadCtl:cmdSubmit")
# link = page.links.find {|l| l.node.text =~ /Download Text File/ }

search_results = agent.submit(search_form)


puts search_results.body

My issues are
1. The cboe returns a file as my system does not have a file handler
for it, it would have invoked a popup for me to save it. how do i
simulate it.
2. how do i confirm if the script reached the popup stage?

Thanks

Seede

1 Answer

Aaron Patterson

8/4/2006 6:03:00 PM

0

Hi,

On Sat, Aug 05, 2006 at 02:15:06AM +0900, junkone@rogers.com wrote:
> HI
> I am trying to download text file from cboe.org site. here is what i
> have done so far
> require 'rubygems'
> require 'mechanize'
> require 'logger'
>
> agent = WWW::Mechanize.new { |a| a.log = Logger.new("mech.log") }
> agent.user_agent_alias = 'Mac Safari'
> page =
> agent.get("http://www.cboe.com/delayedquote/QuoteTableDownload....)
> search_form = page.forms.name("QuoteTableDownload").first
> search_form.fields.name("ucQuoteTableDownloadCtl:txtTicker").value =
> "yhoo"
> link=search_form.fields.name("ucQuoteTableDownloadCtl:cmdSubmit")
> # link = page.links.find {|l| l.node.text =~ /Download Text File/ }
>
> search_results = agent.submit(search_form)
>
>
> puts search_results.body

It looks like the form requires you to "click" a button. Try changing

search_results = agent.submit(search_form)

to this:

search_results = agent.submit(search_form, search_form.buttons.first)

>
> My issues are
> 1. The cboe returns a file as my system does not have a file handler
> for it, it would have invoked a popup for me to save it. how do i
> simulate it.
> 2. how do i confirm if the script reached the popup stage?

Just examine the contents returned from the server to see if they are
correct. If so, save the file, if not, fix the script. Hope this
helps!

--Aaron