0

I am trying to automate the download of a CSV file by using PhantomJS to click on an object on a website.

function() {
    (page.evaluate(function() {
        $("export2csv").click();
    }))
}

If I run this in the Chrome dev-console a CSV file starts downloading.
Chrome displays blob:https://website/seeminglyrandomstring as its source, which means I have no static URL pointing to this file.

If I run it in PhantomJS however, there is no output, just like it finished without any errors. But neither do I get my file. Has this anything to to with the following statement in the official documentation?

The execution is sandboxed, the web page has no access to the phantom object and it can’t probe its own setting.

I am using PhantomJS 2.0.0 on Windows

xenoid
  • 13
  • 7
  • According to [this Q/A](https://stackoverflow.com/questions/27911395/download-file-via-hyperlink-in-phantomjs-using-selenium), phantomjs "would *never proceed with a download request*", so we can assume it doesn't support the download attribute. However, I don't know phantomjs that much and can't be 100% sure it's a duplicate, so I'll let someone with more experience to VTC. – Kaiido Jan 17 '18 at 01:19
  • I will try using Chromedriver with Python for Windows ... – xenoid Jan 18 '18 at 09:13

1 Answers1

0

Because of PhantomJS's limitations, I will try using Chromedriver with Selenium for Python on Windows.

EDIT:

Heres a simple solution:

import time
from selenium import webdriver

#xenoid 18.01.2018


#Starting the driver
chromeOptions = webdriver.ChromeOptions()

#Download directory
prefs = {"download.default_directory" : "C:/temp/"}
chromeOptions.add_experimental_option("prefs",prefs)
#Location to chromedriver
driver = webdriver.Chrome('C:\chromedriver\chromedriver.exe', 
chrome_options=chromeOptions)
driver.get("_URL_TO_WEBSITE_");
#Time it takes for the website to load
time.sleep(5)
#Click the button
button = driver.find_element_by_css_selector("_YOUR_CSS_SELECTOR_'")
button.click()
time.sleep(3)
driver.quit()
xenoid
  • 13
  • 7