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重新启动驱动程序之外,还有其他方法可以解决此问题吗?
如果有人也可以详细说明这种行为,我将非常感激。谢谢。