【发布时间】:2019-02-18 19:34:56
【问题描述】:
Chrome 驱动版本:2.41 Chrome 版本:69.0.3497.92
这是我的代码向一个 webdriver 发送多个请求并进行异常处理:
from selenium import webdriver
from selenium.common.exceptions import *
options = webdriver.ChromeOptions()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
driver = webdriver.Chrome('/usr/local/bin/chromedriver', chrome_options=options)
driver.set_page_load_timeout(30)
for link in links:
try:
driver.get(link)
except TimeoutException as e:
# do something
continue
except Exception as e:
# do some other thing
continue
预期的行为是,如果抛出 TimeoutException,我将继续向下一个链接发出请求,依此类推。但是,我得到的是,当一个 TimeoutException 发生时,所有其余的链接也会抛出 TimeoutExceptions。
这是来自 chrome 记录器的相关日志。
[1536872569.507][SEVERE]: Timed out receiving message from renderer: 29.449 [1536872569.509][INFO]: Timed out. Stopping navigation... [1536872569.509][DEBUG]: DEVTOOLS COMMAND Page.stopLoading (id=1243) { } [1536872569.509][DEBUG]: DEVTOOLS RESPONSE Page.stopLoading (id=1243) { } [1536872569.509][DEBUG]: DEVTOOLS COMMAND Runtime.evaluate (id=1244) { "expression": "1" } [1536872569.510][SEVERE]: Timed out receiving message from renderer: -0.002 [1536872569.513][INFO]: Done waiting for pending navigations. Status: timeout [1536872569.513][INFO]: RESPONSE Navigate timeout (Session info: headless chrome=69.0.3497.92) [1536872569.516][INFO]: COMMAND Navigate { "sessionId": "9caf0bad68147065f14c9c22632cd6d8", "url": "www.example.com" } [1536872569.516][DEBUG]: DEVTOOLS EVENT Page.frameStoppedLoading { "frameId": "620369B66F0605C0CE359F34F9D95E36" } [1536872569.516][DEBUG]: DEVTOOLS RESPONSE Runtime.evaluate (id=1244) { "result": { "description": "1", "type": "number", "value": 1 } } [1536872569.516][INFO]: Waiting for pending navigations... [1536872569.516][DEBUG]: DEVTOOLS COMMAND Runtime.evaluate (id=1245) { "expression": "1" } [1536872569.517][DEBUG]: DEVTOOLS RESPONSE Runtime.evaluate (id=1245) { "result": { "description": "1", "type": "number", "value": 1 } } [1536872599.516][SEVERE]: Timed out receiving message from renderer: 30.000 [1536872599.518][INFO]: Timed out. Stopping navigation... [1536872599.518][DEBUG]: DEVTOOLS COMMAND Page.stopLoading (id=1246) { } [1536872599.518][DEBUG]: DEVTOOLS RESPONSE Page.stopLoading (id=1246) { } [1536872599.518][DEBUG]: DEVTOOLS COMMAND Runtime.evaluate (id=1247) { "expression": "1" } [1536872599.518][SEVERE]: Timed out receiving message from renderer: -0.002 [1536872599.522][INFO]: Done waiting for pending navigations. Status: timeout [1536872599.522][INFO]: RESPONSE Navigate timeout (Session info: headless chrome=69.0.3497.92) [1536872599.524][INFO]: COMMAND Navigate { "sessionId": "9caf0bad68147065f14c9c22632cd6d8", "url": "www.example2.com" }
以下是我将此事件与其他无异常完成的后续请求进行比较时发现的差异。
1) DEVTOOLS EVENT Page.frameStoppedLoading 在向新的“www.example.com”链接发送请求后立即出现。
2) 从上一个链接发送的对DEVTOOLS COMMAND Runtime.evaluate (id=1244) 的响应会在对新 URL 的请求之后记录。
问题:除了使用每个 TimeoutException 重新启动驱动程序之外,还有其他方法可以处理此问题吗?
如果有人也能详细说明这种行为,我将不胜感激。谢谢。
【问题讨论】:
标签: python selenium google-chrome selenium-webdriver google-chrome-devtools