Using Selenium with Python and PhantomJS to download file to filesystem -


i've been grappling using phantomjs/selenium/python-selenium download file filesystem. i'm able navigate through dom , click, hover etc. downloading file is, however, proving quite troublesome. i've tried headless approach firefox , pyvirtualdisplay wasn't working either , unbelievably slow. know casperjs allows file downloads. know how integrate casperjs python or how utilize phantomjs download files. appreciated.

despite question quite old, downloading files through phantomjs still problem. can use phantomjs download link , fetch needed cookies such csrf tokens , on. , can use requests download actually:

import requests selenium import webdriver  driver = webdriver.phantomjs() driver.get('page_with_download_link') download_link = driver.find_element_by_id('download_link') session = requests.session() cookies = driver.get_cookies()  cookie in cookies:      session.cookies.set(cookie['name'], cookie['value']) response = session.get(download_link) 

and in response.content actual file content should appear. can next write open or whatever want.


Comments