使用Selenium与Python和PhantomJS将文件下载到文件系统 [英] Using Selenium with Python and PhantomJS to download file to filesystem

查看:1136
本文介绍了使用Selenium与Python和PhantomJS将文件下载到文件系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用PhantomJS / Selenium / python-selenium来将文件下载到文件系统。
我可以轻松浏览DOM,点击,悬停等。但是,下载文件证明是非常麻烦的。我已经尝试了一个无头的方法与Firefox和pyvirtualdisplay,但这还不能正常工作,是令人难以置信的缓慢。我知道CasperJS允许文件下载。有人知道如何将CasperJS与Python集成,或者如何利用PhantomJS下载文件。非常感谢。

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.

推荐答案

PhantomJS目前不支持文件下载。解决方法的相关问题:

PhantomJS doesn't currently support file downloads. Relevant issues with workarounds:

  • File download
  • How to handle file save dialog box using Selenium webdriver and PhantomJS?

据我所知,至少3个选项:

As far as I understand, you have at least 3 options:


  • 切换到 casperjs (你应该在这里离开python) / li>
  • 尝试在 xvfb

  • 切换到正常的无头浏览器

  • switch to casperjs (and you should leave python here)
  • try with headless on xvfb
  • switch to normal non-headless browsers

这里也有一些可能有帮助的链接:

Here are also some links that might help too:

  • Selenium Headless Automated Testing in Ubuntu
  • XWindows for Headless Selenium (with further links inside)
  • How to run browsers(chrome, IE and firefox) in headless mode?
  • Tutorial: How to use Headless Firefox for Scraping in Linux

这篇关于使用Selenium与Python和PhantomJS将文件下载到文件系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆