【发布时间】:2019-09-07 23:10:22
【问题描述】:
我正在使用 selenium 在 Python 中运行自动化脚本。我已经使用该工具三年了,但从未遇到过这个问题。有谁知道这可能是什么原因造成的?我能够确定错误的原因是在 for 循环中对 driver.get() 的引用,但在 7 次迭代后它会出错。看起来很奇怪,想法?
Unhandled exception in thread started by <function crawl_games_and_store_data.<locals>.handle_incoming_request at 0x104659158>
Traceback (most recent call last):
File "/Users/z003bzf/Documents/personal/python/MLB/src/services/crawler.py", line 160, in handle_incoming_request
driver.get(game_link)
File "/Users/z003bzf/.local/share/virtualenvs/MLB-Ei2Ym8vD/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 333, in get
self.execute(Command.GET, {'url': url})
File "/Users/z003bzf/.local/share/virtualenvs/MLB-Ei2Ym8vD/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 318, in execute
params = self._wrap_value(params)
File "/Users/z003bzf/.local/share/virtualenvs/MLB-Ei2Ym8vD/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 271, in _wrap_value
converted[key] = self._wrap_value(val)
File "/Users/z003bzf/.local/share/virtualenvs/MLB-Ei2Ym8vD/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 276, in _wrap_value
return list(self._wrap_value(item) for item in value)
这是导致问题的代码
for elem in link_lst:
driver.get(elem)
time.sleep(.5)
driver.find_element_by_xpath('//div[@class="box-row batting-row"]')
【问题讨论】:
-
发布问题所在的实际代码...如minimal reproducible example。
-
我在下面添加了我的代码作为答案,因为 cmets 不支持代码语法。
-
您应该编辑您的问题并在此处添加代码和任何其他相关详细信息。
标签: python selenium selenium-webdriver error-handling