<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:times new roman,new york,times,serif;font-size:12pt"><div style="font-family: times new roman,new york,times,serif; font-size: 12pt;">Sell,<br><br>As Mechanize doesn't interpret Javascript, you will need to dissect the function "dataExport". If you need help with that, paste the source for that function here and perhaps we can help more. Or if the website is publicly accessible, let us know the URL and we can take a look at it.<br><br>Matt White<br><br><div style="font-family: times new roman,new york,times,serif; font-size: 12pt;">----- Original Message ----<br>From: Sell Trino &lt;selltrino@gmail.com&gt;<br>To: mechanize-users@rubyforge.org<br>Sent: Tuesday, April 29, 2008 2:23:26 PM<br>Subject: [Mechanize-users] Intercepting an onClick file download<br><br>
Hi,<br><br>I'm having some trouble downloading a .csv file from a particular<br>website.&nbsp; The file isn't part of a url, you need to click on a link in<br>order to get the file sent.&nbsp; I don't know how to get mechanize to<br>correctly identify that.<br><br>Here is the link to the file I'm trying to retrieve:<br><br> &lt;td style="vertical-align: bottom; text-align: center;"&gt;<br> &lt;a href="#" onClick="dataExport( 'csv' ); return false;"&gt;&lt;img<br>src="/img/buttons/bu_csv.gif" width="37" height="17" style="border:<br>none;" alt="Export to CVS"&gt;&lt;/a&gt;<br> &lt;/td&gt;<br><br>Here is my code (partial):<br><br>agent = WWW::Mechanize.new { |a| a.log = Logger.new("mech.log") }<br>agent.keep_alive = false<br>agent.read_timeout = 60 # the page would timeout sometimes<br>url = "<a href="https://website.com/page.php4" target="_blank">https://website.com/page.php4</a>"<br>page = agent.get(url)<br>page.links.text(/Export to CVS/).each {
 |link|<br>&nbsp; file_page = agent.click(link)<br>&nbsp; file_page.save_as('output.csv')<br>&nbsp; return<br>}<br><br>What I get in output.csv is just the original page, not the .csv file.<br> If someone could please help me understand how I can nab the file<br>contents instead, I'd greatly appreciate it.&nbsp; (I actually want to<br>eventually parse the csv within the code, not just save it)<br><br>Thanks!<br>_______________________________________________<br>Mechanize-users mailing list<br><a ymailto="mailto:Mechanize-users@rubyforge.org" href="mailto:Mechanize-users@rubyforge.org">Mechanize-users@rubyforge.org</a><br><a href="http://rubyforge.org/mailman/listinfo/mechanize-users" target="_blank">http://rubyforge.org/mailman/listinfo/mechanize-users</a><br></div></div></div><br>

      <hr size=1>Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile. <a href="http://us.rd.yahoo.com/evt=51733/*http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ "> Try it now.</a></body></html>