1

I'm scraping a weird ASP-based site. I want to download an XML file. To get the download normally, I fill out a form, click "download", then a popup comes up and the file downloads automatically (in both chrome and firefox).

What seems to ultimately trigger the download is a GET request to an 'www.HOST.content/xmlfile.aspx' url which gets a 'content-disposition:attachment' with a filename 'xmldocumentIcareabout.xml'

While I can see this request/response using the developer console in chrome (on the popup page), I do not see these events in 'resource.requested' or 'resource.received' on the Casperjs side.

What I've tried so far:

  • Explicit call to 'this.download('www.HOST.content/xmlfile.aspx')
  • Post call using the form: 'this.download('www.HOST.content/form.aspx',downloadPath,'POST', postBody)' where 'postBody' has all the form information and the __EVENT_TARGET
  • Trying to replicate the GET request with this.open('www.HOST.content/xmlfile.aspx')

What other approaches can be used so that I can catch an automatic download event from a popup window in Casperjs?

pshee
  • 83
  • 8
  • You've seen [this](http://stackoverflow.com/questions/19199641/casperjs-download-csv-file), right? – Artjom B. Nov 04 '15 at 09:41
  • 1
    Yeah, I think I've seen all the related SO posts on this, but none of the solutions have worked. Since the file download is triggered through a popup window, it doesn't then trigger the 'resource.received' event listener. Is there a specific way to set up that listener for the popup window or should it work across all windows? – pshee Nov 04 '15 at 17:28
  • I don't know if it should work for all windows. You can try to add the listener inside of the `withPopup` callback, but it might be too late. Downloading was always very tricky with PhantomJS. There is a [forked PhantomJS version](http://stackoverflow.com/a/31124037/1816580) where there is a specific filedownload listener. – Artjom B. Nov 04 '15 at 20:01

1 Answers1

0

Fixed by calling 'download()' within the popUp frame (in the 'then()' function of 'withPopup()'

pshee
  • 83
  • 8