Re: Downloading TSV files

Keary Suska <[email protected]> Thu, 28 Oct 2010 08:37:57 -0600
Newsgroups gmane.comp.lang.perl.modules.lwp
Message-ID <[email protected]>
On Oct 28, 2010, at 7:43 AM, Meir Guttman wrote:

> Unfortunately, it seems to me that the TSV file I am looking to download is
> by no means static. IMHO it is dynamically generated, using a server side
> JavaScript. The TSV download seems to be initiated by the following
> "onclick" clause:
> 
> <a  class="ExcelLink"
> onclick="javascript:customWindowOpen('/TASE/Pages/Export.aspx?sn=Excelds&Tbl
> Id=0&Titles=en-US_AddColTitles&Columns=en-US_AddColColumns&enumTblType=AllSe
> curities&AddCol=1&ExportType=4', '_blank', 'scrollbars=yes; toolbar=yes;
> menubar=yes; resizable=yes', 800, 450);return false;"
> href="javascript:void(0)">TSV</a>
> 
> And the customWindowOpen javascript is defined as:
> 
> <script language="javascript">
> 
>            function customWindowOpen(strUrl, strWindow, strParams, iWidth, iHeight)
>            {
>                  Var iLeft, iTop;
>                  iLeft = (window.screen.width - iWidth) / 2;
>                  iTop = (window.screen.height - iHeight) / 2;
>                  strParams = strParams + ",width=" + iWidth.toString() +",height=" + iHeight.toString() + ",left=" + iLeft.toString() + ",top=" + iTop.toString();
>                  window.open(strUrl, strWindow, strParams);
>            }
>      </script>

The JavaScript isn't doing anything fancy, just opening a new URL "/TASE/Pages/Export.aspx?sn=Excelds&TblId=0&Titles=en-US_AddColTitles&Columns=en-US_AddColColumns&enumTblType=AllSecurities&AddCol=1&ExportType=4" . You generally don't need to process JavaScript, just be able to grok it enough to send the server what it expects. Using FireFox and a tool like HttpFox or FireBug you can see what is being sent back and forth, and then simply imitate that behavior with your script.

Keary Suska