嗨,我正在测试的页面加载速度太慢,所以我从stackoverflow得知我们可以为driver.get()设置超时时间
但是在尝试超时时,即使我使用了异常处理,我也得到了TimeOutException
这是我的代码
from selenium import webdriver
import time
from selenium.common.exceptions import TimeoutException
driver = webdriver.Chrome()
t = time.time()
driver.set_page_load_timeout(20)
try:
driver.get('https://www.slibuy.com/search?upcoming=store&update=all&uptime=all')
except TimeoutException as e:
driver.execute_script("window.stop();")
print("Exception has been thrown. " + str(e))
print('Time consuming:', time.time() - t)
这是错误消息
Traceback (most recent call last):
File "main.py", line 33, in <module>
driver.get('https://www.slibuy.com/search?upcoming=store&update=all&uptime=all')
File "/home/noobie/anaconda3/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 332, in get
self.execute(Command.GET, {'url': url})
File "/home/noobie/anaconda3/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 320, in execute
self.error_handler.check_response(response)
File "/home/noobie/anaconda3/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message: timeout
(Session info: chrome=69.0.3497.100)
(Driver info: chromedriver=2.42.591071 (0b695ff80972cc1a65a5cd643186d2ae582cd4ac),platform=Linux 4.15.0-36-generic x86_64)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "main.py", line 35, in <module>
driver.execute_script("window.stop();")
File "/home/noobie/anaconda3/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 635, in execute_script
'args': converted_args})['value']
File "/home/noobie/anaconda3/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 320, in execute
self.error_handler.check_response(response)
File "/home/noobie/anaconda3/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message: timeout
(Session info: chrome=69.0.3497.100)
(Driver info: chromedriver=2.42.591071 (0b695ff80972cc1a65a5cd643186d2ae582cd4ac),platform=Linux 4.15.0-36-generic x86_64)
有人可以解释出什么问题吗?