I've been grappling with using PhantomJS/Selenium/python-selenium to download a file to the filesystem. I'm able to easily navigate through the DOM and click, hover etc. Downloading a file is, however, proving to be quite troublesome. I've tried a headless approach with Firefox and pyvirtualdisplay but that wasn't working well either and was unbelievably slow. I know That CasperJS allows for file downloads. Does anyone know how to integrate CasperJS with Python or how to utilize PhantomJS to download files. Much appreciated.
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
Is not posible in that way. You can use other alternatives to download files like wget o curl.
Use firefox to find the right request and selenium to get the values for that and finally use out of to the box to download the file
My use case required a form submission to retrieve the file. I was able to accomplish this using the driver's
execute_async_script()
function.Despite this question is quite old, downloading files through
PhantomJS
is still a problem. But we can use PhantomJS to get download link and fetch all needed cookies such as csrf tokens and so on. And then we can userequests
to download it actually:And now in
response.content
actual file content should appear. We can next write it withopen
or do whatever we want.PhantomJS doesn't currently support file downloads. Relevant issues with workarounds:
As far as I understand, you have at least 3 options:
casperjs
(and you should leave python here)xvfb
Here are also some links that might help too: