python - 用硒打开的 Chrome 页面保持空白
问题描述
我正在尝试保存网页的屏幕截图,为此我正在尝试使用 Selenium。问题是,一旦打开网页,URL 中的“data:”就会保持空白。
这是我的代码:
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_experimental_option('useAutomationExtension', False)
driver = webdriver.Chrome(options=options,executable_path='aPath/chromedriver.exe',service_log_path='aPath/mylog.txt')
driver.get('http://myURL.html')
screenshot=driver.save_screenshot('aPath/my_screenshot.png')
driver.quit()
注意:我检查了我的 chromedriver 版本是否与我的 chrome 浏览器版本兼容。
解决方案
您需要使用chromedriver二进制文件的绝对路径更新Key的值,如下所示: executable_path
service_args
driver = webdriver.Chrome(options=options,executable_path=r'C:\path\to\chromedriver.exe', service_args=["--log-path=C:\\path\\to\\mylog.log"])
您可以在以下位置找到一些相关的讨论:
推荐阅读
- python - 如何使用 python pandas 计算嵌套组比例而不丢失原始行数
- google-apps-script - Google Scripts - 从 google 表格中的单个单元格将多个客人添加到日历活动
- javascript - React:从受控子输入字段更新大型父记录时如何保持性能?
- c# - 与 EF Core 的单向一对一关系
- android - 带有 RecyclerView 的自定义对话框在屏幕上膨胀得非常小
- android - 如何修复 supportFragmentManager?
- php - Cakephp:如何使用 Twig 获取数据库表名列表
- python-3.x - 使用python并行化numpy数组中的属性分配对象
- apache-spark - 使用 JDBC 从 Spark 中的 RDBMS 进行增量和并行读取
- javascript - index.html:42 Uncaught ReferenceError: 函数未定义