无法使用Python Selenium Chrome Ubuntu 20.04下载任何内容

时间:2020-04-04 18:50:11

标签: python selenium google-chrome selenium-webdriver

我无法通过Headless模式的Python在Selenium Chrome中下载文件。我在这里检查了几个答案,大多数答案都是相同的。他们谈论添加首选项和实验选项。

Download with python selenium

Selenium Webdriver: How to Download a PDF File with Python?

Downloading a PDF using Selenium, Chrome and Python

Downloading with chrome headless and selenium

这些都没有帮助,我开始怀疑这是否与我的环境有关。

Ubuntu:20.04

Python:3.8.2

Chromeium浏览器: 铬80.0.3987.162快照

铬驱动器: ChromeDriver 80.0.3987.162(f2c5dd6138153bb0658091205bd1a1717f16081a-refs / branch-heads / 3987 @ {#1034})

这是不起作用的基本示例代码。它已完成,没有任何错误,但文件从未下载。

p { margin-top: 0px;margin-bottom: 0px;line-height: 1.15; }
body { font-family: 'Arial';font-style: Normal;font-weight: normal;font-size: 14.6666666666667px; }.Normal { telerik-style-type: paragraph;telerik-style-name: Normal;border-collapse: collapse; }.TableNormal { telerik-style-type: table;telerik-style-name: TableNormal;border-collapse: collapse; }.s_4C87DD5E { telerik-style-type: local;font-family: 'Arial';font-size: 14.6666666666667px;color: #000000; }.s_8D20FCAB { telerik-style-type: local;font-family: 'Arial';font-size: 14.6666666666667px;color: #000000;text-decoration: underline; }.p_53E06EE5 { telerik-style-type: local;margin-left: 0px; } 

我已经附上了两个屏幕截图,但是下载页面始终显示为空白页面。

测试文件下载站点:

test page after button click

Chrome下载页面:

Chrome Download page

请帮助!

更新:我已经删除了chrome的snap版本,它似乎工作得更好。我可以将文件下载到自定义目录。必须是快照版本的错误。

1 个答案:

答案 0 :(得分:0)

我刚提交了a bug on this。从本文中可以看到,问题在于Snap使用的下载文件夹指向Snap设置,而完全忽略了您的IMG_DIR设置。

您应该能够通过以下方法来确认这一点:在下载时停止测试,然后直接在浏览器“下载”中查找用于下载的文件夹。