当我在本地PC上运行脚本时,一切正常,但当我在服务器上运行脚本时(nohup),错误。驱动程序版本与程序版本相同。python3.10
错误:
NoSuchWindowException: Message: no such window: target window already closed from unknown error: web view not found (Session info: chrome=110.0.5481.100)`
or WebDriverException: Message: disconnected: Unable to receive message from renderer (failed to check if window was closed: disconnected: not connected to DevTools) (Session info: headless chrome=110.0.5481.100)
当尝试driver.window_handles
(找出有多少窗口),另一个错误:
selenium.common.exceptions.WebDriverException: Message: disconnected: not connected to DevTools (failed to check if window was closed: disconnected: not connected to DevTools) (Session info: chrome=110.0.5481.100).
也许有人遇到或知道问题是什么?
代码:
options = webdriver.ChromeOptions()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('disable-infobars')
options.add_argument("user-agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.129 Safari/537.36")
loc = os.getcwd()
serv = Service("%s/chromedriver" % loc)
os.chmod("%s/chromedriver" % loc, 755) driver: webdriver.Chrome = webdriver.Chrome(options=options, service=serv) driver.get("any_link")
1条答案
按热度按时间pprl5pva1#
我遇到了同样的错误。本地PC工作正常,远程或虚拟工作正常,直到我从机器断开。我认为这个错误与远程机器上的用户会话有关,当断开连接或屏幕保护程序与它控制的浏览器示例的连接松动时。对我有效的方法是:切换睡眠和屏幕模式从不(如果windows框).