casperjs download file without specifying url

后端 未结 4 532
[愿得一人]
[愿得一人] 2020-12-04 00:04

Is there any way to download CSV file with casperjs without specifying download URL? I am trying to download CSV file whose URL is dynamically generated when I click the dow

4条回答
  •  青春惊慌失措
    2020-12-04 00:55

    I have found a solution for that. It is not very clean but it works :

    You need to build an global array, which associates every resource.received having a filename attached.

    fileInfos[url]= parse_filename_from_responseHeader(resource)
    

    If url is the resource you want to download, try open(url) first. This will trigger the resiyrce.received event, parse the header and update the global array.

    Now, before launching the casper.download(url), look for fileInfos[url].

    You will find the filename corresponding to the url in the fileInfos array. I can elaborate on the solution if needed, but since the question is already a few years old,

    I'll wait for the next poke to elaborate.

提交回复
热议问题