使用 selenium 和 chromedriver 时出现 BrokenPipeError

乔尔·马修

执行以下代码以尝试抓取网站的索引页面,并尝试识别包含登录文本的元素,如下所示:

from selenium import webdriver
import os
chromedriver = "/usr/bin/chromedriver"
os.environ["webdriver.chrome.driver"] = chromedriver
driver = webdriver.Chrome(chromedriver)
my_url = 'https://www.pastest.com/'
driver.implicitly_wait(15)
driver.get(my_url)
driver.quit()
p_element = driver.find_element_by_class_name('popup-link')
print(p_element.text)

我收到以下错误:

Traceback (most recent call last):
  File "scrape_pastest.py", line 17, in <module>
    p_element = driver.find_element_by_class_name('popup-link')
  File "/home/joel/.local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 555, in find_element_by_class_name
    return self.find_element(by=By.CLASS_NAME, value=name)
  File "/home/joel/.local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 955, in find_element
    'value': value})['value']
  File "/home/joel/.local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 310, in execute
    response = self.command_executor.execute(driver_command, params)
  File "/home/joel/.local/lib/python3.6/site-packages/selenium/webdriver/remote/remote_connection.py", line 466, in execute
    return self._request(command_info[0], url, body=data)
  File "/home/joel/.local/lib/python3.6/site-packages/selenium/webdriver/remote/remote_connection.py", line 489, in _request
    self._conn.request(method, parsed_url.path, body, headers)
  File "/usr/lib/python3.6/http/client.py", line 1239, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/usr/lib/python3.6/http/client.py", line 1285, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/usr/lib/python3.6/http/client.py", line 1234, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/usr/lib/python3.6/http/client.py", line 1065, in _send_output
    self.send(chunk)
  File "/usr/lib/python3.6/http/client.py", line 986, in send
    self.sock.sendall(data)
BrokenPipeError: [Errno 32] Broken pipe

driver.implicitly_wait(15)当我第一次遇到错误时,我专门添加了该行来处理超时错误。我也试过selenium_client.set_page_load_timeout(10),但这也无济于事。

这个问题是什么原因造成的?我该如何解决?

匿名

quit司机打电话后find_element_by_class_name

根据 selenium.webdriver文档

放弃()

Closes the browser and shuts down the ChromeDriver executable that is started when starting the ChromeDriver

driver.quit 关闭浏览器会话,之后您将无法使用驱动程序来搜索元素。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

使用ChromeDriver 2.43和Chrome通过Selenium连接到Chrome时超时,重试...错误

org.openqa.selenium.WebDriverException:断开连接:使用ChromeDriver未连接到DevTools错误Chrome使用Selenium和Java

超时从渲染器接收消息:300.000错误,在使用ChromeDriver和Windows通过Selenium和Java在Windows之间切换时

org.apache.commons.exec.ExecuteException:ChromeDriver Chrome Selenium和TestNG Suite出现错误,进程退出

使用Selenium和python在Chromedriver中保存扩展设置

使用chromedriver和Selenium创建Python可执行文件

Heroku:使用Selenium时找不到chromedriver

使用Selenium时是否需要安装Chrome或仅安装chromedriver?

Selenium和Chromedriver-无法单击元素

如何使用Selenium和JavaFX禁用ChromeDriver的日志记录

WebDriverException:消息:服务/ content / chromedriver意外退出。状态代码为:-6(使用ChromeDriver Google Colab和Selenium)

如何使用Selenium和Chromedriver查找元素

启动Selenium Chromedriver时使用两个excludeSwitch?

使用Selenium和ChromeDriver,自动缩放打印页面的大小

禁用所有使用ChromeDriver和Selenium的下载

地址栏显示数据:,同时尝试通过Selenium和Python使用ChromeDriver Chrome进行抓取

使用ChromeDriver和Selenium设置max属性时,无法使用send_keys将日期作为文本发送到datepicker字段

SessionNotCreatedException:此版本的ChromeDriver仅支持使用ChromeDriver的Chrome版本84和通过Selenium和Python的Chrome

无法通过Selenium和Python使用ChromeDriver和Chrome登录eBay帐户

SessionNotCreatedException:此版本的ChromeDriver仅支持使用ChromeDriver的Chrome版本79,以及通过Selenium和JavaScript的Chrome

使用 Selenium 和 Java 单击按钮时出现问题

Selenium 3.7.1 (Java) 和 ChromeDriver 2.33.5

使用 chromedriver 从 Selenium 打印 PDF

使用 selenium 和 python 加载 cookie 时出现问题

chromedriver 在 Windows 上使用 selenium 和 Google Collab 的路径问题

需要帮助使用 Selenium-Chromedriver 和 Python3,浏览器自动化

Python Selenium 再次使用 Chromedriver

通過 Selenium 和 Python 使用代理的 ChromeDriver 日誌中的錯誤

如何解決 TypeError: 'module' object is not callable 錯誤使用 Selenium 和 ChromeDriver