用 selenium 打开的 Chrome 页面保持空白 [英] Chrome page opened with selenium remains blank

查看:115
本文介绍了用 selenium 打开的 Chrome 页面保持空白的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试保存网页的屏幕截图,为此我正在尝试使用 Selenium.问题是,一旦打开网页,它就会保持空白,网址中带有data:".

I am trying to save a screenshot of a webpage, to do so I am trying to use Selenium. The problem is that once the webpage is opened, it stays blank with "data:" in the URL.

这是我的代码:

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 浏览器版本兼容.

NB: I have checked that my chromedriver version is compatible with my chrome browser version.

推荐答案

感谢大家的帮助,其实 Guy 说得对,我必须指定端口:

Thanks for your help guys, actually Guy was right, I had to specify the port:

options.add_argument('--remote-debugging-port=9222')

现在可以了!

这篇关于用 selenium 打开的 Chrome 页面保持空白的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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