简体   繁体   English

使用selenium和chromedriver时出现BrokenPipeError

[英]BrokenPipeError while using selenium and chromedriver

While executing the following code to try to scrape a website's index page, and attemptying to identify an element containing login text, as below: 执行以下代码以尝试抓取网站的索引页面,并尝试识别包含登录文本的元素时,如下所示:

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)

I get the following error: 我收到以下错误:

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

I had specifically added the line driver.implicitly_wait(15) to take care of any error of timeout, when I first encountered the error. 当我第一次遇到错误时,我特意添加了行driver.implicitly_wait(15)来处理任何超时错误。 I had also tried selenium_client.set_page_load_timeout(10) , but that didn't help either. 我也尝试过selenium_client.set_page_load_timeout(10) ,但这也没有帮助。

What's this problem due to? 这个问题是由于什么原因造成的? How can I fix it? 我该如何解决?

quit the driver after calling find_element_by_class_name . 调用find_element_by_class_namequit驱动程序。

According to selenium.webdriver docs : 根据selenium.webdriver 文档

quit() 放弃()

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

driver.quit closes the browser session and you can not use the driver after that to search for elements. driver.quit关闭浏览器会话,之后您无法使用驱动程序来搜索元素。

暂无
暂无

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

相关问题 chromedriver 使用硒进行刮擦 - chromedriver using selenium for scraping 在python中使用Selenium chromedriver - Using selenium chromedriver with python 将chromedriver与Selenium结合使用时,如何更正超时错误? - While using the chromedriver with Selenium, how do I correct a timeout error? (TypeError: &#39;module&#39; object is not callable) while using chromedriver of selenium - (TypeError: 'module' object is not callable) while using chromedriver of selenium 在Python中使用套接字模块时,如何避免出现BrokenPipeError? - How do I avoid a BrokenPipeError while using the sockets module in Python? 在 selenium/python/ubuntu 中使用 chromedriver - Using chromedriver with selenium/python/ubuntu selenium webdriver BrokenPipeError(超时问题) - selenium webdriver BrokenPipeError (timeout issue) Chromedriver 仅支持 BMP 错误中的字符,同时使用 ChromeDriver Chrome 使用 Selenium Python 将 Emoji 发送到 Tkinter 的 label() 文本框 - Chromedriver only supports characters in the BMP error while sending Emoji with ChromeDriver Chrome using Selenium Python to Tkinter's label() textbox SyntaxError:在使用 Selenium 和 ChromeDriver 时扫描三引号字符串文字时出现 EOF? - SyntaxError: EOF while scanning triple-quoted string literal while using Selenium and ChromeDriver? 在使用 ChromeDriver 和 Chrome 使用 Selenium 访问应用程序时访问消息之前检查您的浏览器 - Checking your browser before accessing message while accessing an application using ChromeDriver and Chrome using Selenium
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM