Selenium-Phantomjs download csv

I am trying to download (save to disk) a CSV file using PhantomJS from a dialog box. Using a firefox profile, this would be quite simple by setting the properties of the browser profile. Any suggestions on how the excel file can be downloaded in phantomjs?

Here's how to do it with the firefox driver:

profile = webdriver.firefox.firefox_profile.FirefoxProfile() profile.set_preference("browser.download.folderList",2) profile.set_preference("browser.download.dir",self.opts['output_dir']) profile.set_preference('browser.helperApps.neverAsk.saveToDisk', ('application/octet-stream,application/msexcel')) 

I am using the Phantomjs driver:

 webdriver.PhantomJS(service_args=['--ignore-ssl-errors=true','--local-storage-path=/tmp']) 

and finding a way to set properties that can override the save to disk and set the MIME data type. Currently, without setting properties, the PhantomJS driver does not download the file.

I read links about avoiding dialog box, etc., but in this case it is necessary.

+6
source share
1 answer

I recently struggled with a similar problem. However, in the end, I switched the web driver because it makes it easy to access network traffic. This means that if the file is not directly on the page and rather migrated, you do not see it in phantom. There are several people working on the work, but I found that most of my files were transferred, and therefore it was easier for me to collect network traffic using the web driver + firebug + net export.

However in phantomjs a very hacky way to do this would be something like this:

 phantomjs.exe file_to_run.js > my_log.txt 

If you just save the contents of the console to a file. However, you will probably get errors and other messages in your file. You can clear it, since you are only looking for cdv.

From my understanding, PhantomJS is limited, as the developer has a very specific idea of ​​how it should be. For example, they stopped supporting flash. There is no easy way to upload and save files as you can in firefox. You can launch another web browser and load through it. However, I think the easiest way to do this is to use CasperJS, which plays great with PhantomJS.

A good example of using casperJS to download files can be found here: casperjs download csv file

I believe that the main problem with using casper is that large files are poorly supported. Is there a specific reason why you prefer to use a mute browser?

0
source

All Articles