简体   繁体   English

Python Selenium - 如何修复 WebDriverException:消息:目标框架已分离

[英]Python Selenium - How to fix WebDriverException: Message: target frame detached

I am coding a program that crawls through a search query.我正在编写一个通过搜索查询爬行的程序。

  1. scraps all titles from the first query page从第一个查询页面中删除所有标题
  2. clicks each link of each title and scraps main body of the link and exits单击每个标题的每个链接并删除链接的主体并退出
  3. moves onto the next page移动到下一页

It works fine for most, and it did for 480 titles last night.它对大多数人来说都很好,昨晚它为 480 个标题做了。 But with the same code, it keeps returning the following.但是使用相同的代码,它会不断返回以下内容。

And at different titles, so once, an error might pop up on the 8th title of the 2nd query page, and another time, an error pops up on 6th title of first page and so.并且在不同的标题上,有一次,第二个查询页面的第8个标题可能会弹出一个错误,另一次,第一页的第6个标题会弹出一个错误,依此类推。

I am utterly baffled as to why it was fine before, and why it is acting the way it is now.我完全不明白为什么它以前很好,为什么它现在这样。 I would appreciate some pointers.我会很感激一些指示。

I am working with Anaconda - Jupyter Notebook, Selenium (4.1.0.) and Python.我正在使用 Anaconda - Jupyter Notebook、Selenium (4.1.0.) 和 Python。

WebDriverException                        Traceback (most recent call last)
<ipython-input-100-21e892bd2f24> in <module>
      1 #to_next_page(browser)
----> 2 crawl_page(browser)
      3 #x = XPath_finder(10, browser)
      4 #x.click()

<ipython-input-95-32c6665608a1> in crawl_page(browser)
     10     # 본문 구하는 부분
     11     for i, _ in enumerate(page_titles, 1):
---> 12         XPATH = XPath_finder(i, browser)
     13         XPATH.click()
     14         bs2 = BeautifulSoup(browser.page_source, 'html.parser')

<ipython-input-96-1904e01f1b97> in XPath_finder(i, browser)
      1 def XPath_finder(i, browser):
----> 2     elements = browser.find_elements(By.CLASS_NAME, 'txt_wrap')
      3     target = elements[i-1].find_element(By.TAG_NAME, 'a')
      4     return target

C:\ProgramData\Anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py in find_elements(self, by, value)
   1277         # Return empty list if driver returns null
   1278         # See https://github.com/SeleniumHQ/selenium/issues/4555
-> 1279         return self.execute(Command.FIND_ELEMENTS, {
   1280             'using': by,
   1281             'value': value})['value'] or []

C:\ProgramData\Anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py in execute(self, driver_command, params)
    422         response = self.command_executor.execute(driver_command, params)
    423         if response:
--> 424             self.error_handler.check_response(response)
    425             response['value'] = self._unwrap_value(
    426                 response.get('value', None))

C:\ProgramData\Anaconda3\lib\site-packages\selenium\webdriver\remote\errorhandler.py in check_response(self, response)
    245                 alert_text = value['alert'].get('text')
    246             raise exception_class(message, screen, stacktrace, alert_text)  # type: ignore[call-arg]  # mypy is not smart enough here
--> 247         raise exception_class(message, screen, stacktrace)
    248 
    249     def _value_or_default(self, obj: Mapping[_KT, _VT], key: _KT, default: _VT) -> _VT:

WebDriverException: Message: target frame detached
  (Session info: chrome=100.0.4896.88)```

As you are seeing the error message...当您看到错误消息时...

WebDriverException: Message: target frame detached

...indiscriminately one possible reason can be incompatibility between the version of the binaries you are using. ...不加选择地一个可能的原因可能是您使用的二进制文件版本之间的不兼容


Solution解决方案

Ensure that:确保这件事:


tl; tl; dr博士

Supported platforms 支持的平台

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Python selenium - WebDriverException:目标框架分离 - 用于登录按钮 - Python selenium - WebDriverException: target frame detached - for Login button selenium.common.exceptions.WebDriverException:消息:已断开连接:通过Python通过ChromeDriver和Selenium收到了Inspector.detached事件 - selenium.common.exceptions.WebDriverException: Message: disconnected: received Inspector.detached event with ChromeDriver and Selenium through Python 如何解决“WebDriverException: Message: TypeError: can&#39;t access dead object”并使用 Selenium 和 Python 等待帧可用 - How to address “WebDriverException: Message: TypeError: can't access dead object” and wait for a frame to be available using Selenium and Python 代码抛出在 selenium/python 中分离的随机目标帧 - Code throws random target frame detached in selenium/python chrome更新后,消息:目标框架分离 - After chrome update, Message: target frame detached Python / Selenium:WebDriverException:消息:u为空&#39; - Python / Selenium: WebDriverException: Message: u'a is null' python selenium:WebDriverException:消息:chrome无法访问 - python selenium: WebDriverException: Message: chrome not reachable selenium.common.exceptions.WebDriverException:消息:服务geckodriver意外退出。 状态代码为:-11-如何解决? - selenium.common.exceptions.WebDriverException: Message: Service geckodriver unexpectedly exited. Status code was: -11 - How to fix? 如何修复“WebDriverException:消息:连接被拒绝”? - How to fix "WebDriverException: Message: connection refused"? selenium.common.exceptions.WebDriverException:消息:在 Python selenium 4 - selenium.common.exceptions.WebDriverException: Message: in Python selenium 4
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM