rossbertoloni Posted April 2, 2009 Share Posted April 2, 2009 Hi Any idea how I can use curl/snoopy to download file from Javascript based submit button?The file name in url http://localhost:8080/test/test_20090319.zip changes every day. Here is the form page(test.jsp) and LiveHTTPHeader output. <html> <head> <title>Untitled</title> <SCRIPT language="JavaScript1.2"> function poponload() { var url='http://localhost:8080/test/test_20090319.zip'; testwindow= window.open (url); } </script> </head> <body> <form method="GET" action="test.jsp" onsubmit="javascript:poponload()"> <input type="submit" name="download" value="OK" /> </form> </body> </html> ---------------- ==================================== http://localhost:8080/test/test.jsp?download=OK GET /test/test.jsp?download=OK HTTP/1.1 Host: localhost:8080 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: en-us,en;q=0.5 Accept-Encoding: gzip,deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 300 Connection: keep-alive Referer: http://localhost:8080/test/test.jsp Cookie: JSESSIONID=xb3v6b3lo1qb HTTP/1.x 200 OK Date: Wed, 01 Apr 2009 23:47:18 GMT Server: Jetty/5.1.x (Windows XP/5.1 x86 java/1.5.0_04 Content-Type: text/html;charset=ISO-8859-1 Content-Length: 441 Quote Link to comment Share on other sites More sharing options...
Brian W Posted April 2, 2009 Share Posted April 2, 2009 if you use the code tags around your php or even html snippets, you will likely get more help [ code ]Like this but without the spaces in the tags[ /code ] would be Like this but without the spaces in the tags How do you plan on finding out what the filename is everyday? Quote Link to comment Share on other sites More sharing options...
rossbertoloni Posted April 2, 2009 Author Share Posted April 2, 2009 I was hoping by being able to invoke the javascript:poponload using curl I don't need to specify the exact file name.(or is it too wishfull ?) The file name always ends with _YYYYMMDD.zip . Reposting: Hi Any idea how I can use curl/snoopy to download file from Javascript based submit button?The file name in url http://localhost:8080/test/test_20090319.zip changes every day. Here is the form page(test.jsp) and LiveHTTPHeader output. <html> <head> <title>Untitled</title> <SCRIPT language="JavaScript1.2"> function poponload() { var url='http://localhost:8080/test/test_20090319.zip'; testwindow= window.open (url); } </script> </head> <body> <form method="GET" action="test.jsp" onsubmit="javascript:poponload()"> <input type="submit" name="download" value="OK" /> </form> </body> </html> LiveHTTPHeader output. ==================================== http://localhost:8080/test/test.jsp?download=OK GET /test/test.jsp?download=OK HTTP/1.1 Host: localhost:8080 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: en-us,en;q=0.5 Accept-Encoding: gzip,deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 300 Connection: keep-alive Referer: http://localhost:8080/test/test.jsp Cookie: JSESSIONID=xb3v6b3lo1qb HTTP/1.x 200 OK Date: Wed, 01 Apr 2009 23:47:18 GMT Server: Jetty/5.1.x (Windows XP/5.1 x86 java/1.5.0_04 Content-Type: text/html;charset=ISO-8859-1 Content-Length: 441 Quote Link to comment Share on other sites More sharing options...
MadTechie Posted April 2, 2009 Share Posted April 2, 2009 So you need to pull out a filename from a webpage and The file name always ends with _YYYYMMDD.zip how about an over complicated untested script <?php $DATA= <<<DATA <html> <head> <title>Untitled</title> <SCRIPT language="JavaScript1.2"> function poponload() { var url='http://localhost:8080/test/test_20090319.zip'; testwindow= window.open (url); } </script> </head> <body> <form method="GET" action="test.jsp" onsubmit="javascript:poponload()"> <input type="submit" name="download" value="OK" /> </form> </body> </html> DATA; if (preg_match('/\'([^\']*?(?:19|20)[0-9]{2}(?:0[1-9]|1[012])(?:0[1-9]|[12][0-9]|3[01])\.zip)\'/i', $DATA, $regs)) { $result = $regs[1]; } echo $result; ?> Quote Link to comment Share on other sites More sharing options...
rossbertoloni Posted April 3, 2009 Author Share Posted April 3, 2009 Thanks. My bad, I should have provided more details. What I'm really trying to do is creating a shell job which everyday downloads the zip file from a site. The path to the file (http://localhost:8080/test/test_20090319.zip) is actually created on the fly by javascript when the user presses the download button. So the the content of the page does not contain the file path/name . I guess my question is how I can have curl call the javascript to download the file ? Ross Quote Link to comment Share on other sites More sharing options...
corbin Posted April 3, 2009 Share Posted April 3, 2009 cURL cannot execute JS as it does not have a JS engine. You will have to parse the information out of the page, most likely via regular expressions. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.