我在 Python 和 Selenium 框架的一个基本问题上失败了。我想要做的就是循环阅读元素的文本。到目前为止,我可以参考该元素并阅读文本。但是当我.text在无限循环中访问该属性时,我在很短的时间内收到以下错误:
Traceback (most recent call last):
File "C:\Users\lucci\AppData\Local\Programs\Python\Python35\lib\site-packages\urllib3\connection.py", line 159, in _new_conn
(self._dns_host, self.port), self.timeout, **extra_kw)
File "C:\Users\lucci\AppData\Local\Programs\Python\Python35\lib\site-packages\urllib3\util\connection.py", line 80, in create_connection
raise err
File "C:\Users\lucci\AppData\Local\Programs\Python\Python35\lib\site-packages\urllib3\util\connection.py", line 70, in create_connection
sock.connect(sa)
OSError: [WinError 10048] Normalerweise darf jede Socketadresse (Protokoll, Netzwerkadresse oder Anschluss) nur jeweils einmal verwendet werden
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\lucci\AppData\Local\Programs\Python\Python35\lib\site-packages\urllib3\connectionpool.py", line 600, in urlopen
chunked=chunked)
File "C:\Users\lucci\AppData\Local\Programs\Python\Python35\lib\site-packages\urllib3\connectionpool.py", line 354, in _make_request
conn.request(method, url, **httplib_request_kw)
File "C:\Users\lucci\AppData\Local\Programs\Python\Python35\Lib\http\client.py", line 1107, in request
self._send_request(method, url, body, headers)
File "C:\Users\lucci\AppData\Local\Programs\Python\Python35\Lib\http\client.py", line 1152, in _send_request
self.endheaders(body)
File "C:\Users\lucci\AppData\Local\Programs\Python\Python35\Lib\http\client.py", line 1103, in endheaders
self._send_output(message_body)
错误消息指出每个套接字地址只能使用一次。产生上述错误的代码如下:
text_status = WebDriverWait(driver, TIMEOUT).until(EC.presence_of_element_located((By.CLASS_NAME, "text--34J_5 uppercase--ii2bO font-small--19CMC")))
if text_status is not None:
print("Found status")
while True:
print(text_status.text)
我将非常感谢您的帮助。我只想实时访问元素的文本。文本可以相对较快地更改(大约每秒 2 次)。谁能告诉我该怎么做或我的错误在哪里?
神不在的星期二
aluckdog
相关分类