python - 如果我加载视频,python selenium 会给我 TimeoutException
问题描述
我尝试创建一个抓取整个网站的功能。今天得到一个 TimeoutException ......
Traceback (most recent call last):
File "D:/Entwicklung/example/crawler/crawler.py", line 46, in crawl
driver.get(tmp)
File "C:\Users\test\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 333, in get
self.execute(Command.GET, {'url': url})
File "C:\Users\test\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Users\test\AppData\Local\Programs\Python\Python37\lib\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=75.0.3770.142)
当我将视频的 url 传递给 driver.get() 函数时,会触发 TimeoutException。我的循环一直在运行,但是 TimeoutException 之后的每个 driver.get() 调用也会触发 TimeoutException。为什么会这样?
while len(diff) > 0:
tmp = diff.pop()
visited.add(tmp)
driver.get(tmp)
elements = driver.find_elements_by_tag_name("a")
for element in elements:
href = element.get_attribute('href')
if href is None:
continue
else:
if main_url in href:
links.add(href)
diff = links.difference(visited)
解决方案
您的代码正在达到此默认超时,这就是您看到该消息的原因。
您是否尝试过使用Waits?他们在进入下一个代码块之前给了 Selenium 更多的时间。
找到另一个博客:处理 Selenium 超时。他们修改了 Selenium 的默认超时设置。
推荐阅读
- javalite - ActiveWeb:在模板中调用时模型设置器/获取器不起作用
- javascript - 在 React + Redux 中创建输入组件并控制多个表单状态
- database - DB2:涉及多个表的更新查询
- rust - `return 5;` 是 Rust 中的语句或表达式吗?
- python - 如何使用键对 Pandas DataFrame 进行排序?
- mysql - MySQL 从最后 50 行中选择最高的
- rust - 什么是清除和重用 Rust PathBuf 的跨平台方法?
- sql-server - SQL Server 2014 上的 SSRS 2016
- reactjs - How do access methods from one component in a different component in react.js?
- javascript - 根据条件限制复选框