[英]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_name
后quit
驱动程序。
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.