from selenium import webdriver
from selenium.webdriver.common.by import By
driver=webdriver.Chrome()
driver.get("https://en.wikipedia.org/wiki/Main_Page")
driver.implicitly_wait(5)
statistic=driver.find_element(By.CSS_SELECTOR,value=".articlecount a")
print(statistic.text)
我试图从Wikipedia拆解一些文章,但Im却发现这一错误。 我不敢肯定会做些什么,因为选择名称正确,我增加了等候时间。
Traceback (most recent call last):
File "C:Users38161PycharmProjectspythonProject5inspection.py", line 7, in <module>
statistic=driver.find_element(By.CSS_SELECTOR,value=".articlecount a")
File "C:Users38161PycharmProjectspythonProject5venvlibsite-packagesseleniumwebdriver
emotewebdriver.py", line 742, in find_element
return self.execute(Command.FIND_ELEMENT, {"using": by, "value": value})["value"]
File "C:Users38161PycharmProjectspythonProject5venvlibsite-packagesseleniumwebdriver
emotewebdriver.py", line 348, in execute
self.error_handler.check_response(response)
File "C:Users38161PycharmProjectspythonProject5venvlibsite-packagesseleniumwebdriver
emoteerrorhandler.py", line 229, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":".articlecount a"}
(Session info: chrome=120.0.6099.109); For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors#no-such-element-exception
Stacktrace:
GetHandleVerifier [0x00007FF723BC4D02+56194]
(No symbol) [0x00007FF723B304B2]
(No symbol) [0x00007FF7239D76AA]
(No symbol) [0x00007FF723A216D0]
(No symbol) [0x00007FF723A217EC]
(No symbol) [0x00007FF723A64D77]
(No symbol) [0x00007FF723A45EBF]
(No symbol) [0x00007FF723A62786]
(No symbol) [0x00007FF723A45C23]
(No symbol) [0x00007FF723A14A45]
(No symbol) [0x00007FF723A15AD4]
GetHandleVerifier [0x00007FF723F3D5BB+3695675]
GetHandleVerifier [0x00007FF723F96197+4059159]
GetHandleVerifier [0x00007FF723F8DF63+4025827]
GetHandleVerifier [0x00007FF723C5F029+687785]
(No symbol) [0x00007FF723B3B508]
(No symbol) [0x00007FF723B37564]
(No symbol) [0x00007FF723B376E9]
(No symbol) [0x00007FF723B28094]
BaseThreadInitThunk [0x00007FFC06607344+20]
RtlUserThreadStart [0x00007FFC067426B1+33]