curl javascript

2009-04-02
2013-05-30
  • ross bertoloni
    ross bertoloni
    2009-04-02

    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_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

     
    • red neck *
      red neck *
      2009-04-02

      You can get the url parsing the response and send a new request to the url extracted.

      Example:

      <?php

      include "Snoopy.class.php";
      $snoopy = new Snoopy;
         
      $snoopy->fetch("http://localhost:8080/test.jsp");
      $response = $snoopy->results;

      preg_match("#var url\=\'(.*?)\'\;#", $response, $url_extracted);

      $snoopy->fetch( $url_extracted[1] );
      $content_of_file = $snoopy->results;

      header('Content-type: application/zip');
      header('Content-Disposition: attachment; filename="'.date("Ymd").'.zip"');
      print $content_of_file;

      ?>

      Do you understand ?
      ;)

      Good lucky

       
      • ross bertoloni
        ross bertoloni
        2009-04-03

        Thanks.
        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 content of the page does not contain the file path/name . So I can't parse the page looking for the url.

         
  • Gary Bickford
    Gary Bickford
    2009-09-22

    Take a look at the javascript.  It may be in a separate file, but you can download that as well.   All the data the javascript uses is available to you as well, so it should not be too difficult to replicate whatever the javascript does.  It is possible that the javascript code itself changes as well, but that is very unlikely.