我正在试着做一个Facebook市场刮刀。我用的是Microsoft Edge,每次我运行代码时,它都会给我一些错误,我不知道如何修复。这是我到目前为止所拥有的全部,它应该打印汽车的年份和名称。
2009款本田雅阁
from selenium import webdriver
from selenium.webdriver.edge.service import Service
import time
from selenium.webdriver.common.by import By
s=Service('C:\\Users\\CPM\\Downloads\\edgedriver_win64 (3) msedgedriver.exe')
driver = webdriver.Edge(service=s)
url = 'https://www.facebook.com'
driver.get(url)
time.sleep((20))
url = 'https://www.facebook.com/marketplace/category/vehicles?minPrice=0&maxPrice=5000&maxMileage=150000&minMileage=0&sortBy=creation_time_descend&topLevelVehicleType=car_truck&exact=false'
driver.get(url)
time.sleep(5)
elements = driver.find_element(By.CLASS_NAME,'x1i10hfl xjbqb8w x6umtig x1b1mbwd xaqea5y xav7gou x9f619 x1ypdohk xt0psk2 xe8uvvx xdj266r x11i5rnm xat24cr x1mh8g0r xexx8yu x4uap5 x18d9i69 xkhd6sd x16tdsg8 x1hl2dhg xggy1nq x1a2a7pz x1heor9g x1lku1pv')
for ele in elements:
print(ele.get_attribute('title'))
我已经尝试了不同的类名并修复了函数名,但仍然出现这些错误,
DevTools listening on ws://127.0.0.1:63009/devtools/browser/99d7d32b-bcb8-49d3-bce9-a737cb9b9fef
[12308:2292:1127/164624.744:ERROR:edge_auth_errors.cc(450)] EDGE_IDENTITY: Get Default OS Account failed: Error: Primary Error: kImplicitSignInFailure, Secondary Error: kAccountProviderFetchError, Platform error: 0, Error string:
[12308:2292:1127/164646.905:ERROR:fallback_task_provider.cc(124)] Every renderer should have at least one task provided by a primary task provider. If a "Renderer" fallback task is shown, it is a bug. If you have repro steps, please file a new bug and tag it as a dependency of crbug.com/739782.
Traceback (most recent call last):
File "c:\Users\CPM\Downloads\rubiks_cube-master\rubiks_cube-master\new folder\improvedscraper.py", line 19, in <module>
elements = driver.find_element(By.CLASS_NAME,'x1i10hfl xjbqb8w x6umtig x1b1mbwd xaqea5y xav7gou x9f619 x1ypdohk xt0psk2 xe8uvvx xdj266r x11i5rnm xat24cr x1mh8g0r xexx8yu x4uap5 x18d9i69 xkhd6sd x16tdsg8 x1hl2dhg xggy1nq x1a2a7pz x1heor9g x1lku1pv')
File "C:\Users\CPM\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\selenium\webdriver\remote\webdriver.py", line 861, in find_element
return self.execute(Command.FIND_ELEMENT, {"using": by, "value": value})["value"]
File "C:\Users\CPM\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\selenium\webdriver\remote\webdriver.py", line 444, in execute
self.error_handler.check_response(response)
File "C:\Users\CPM\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\selenium\webdriver\remote\errorhandler.py", line 249, 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":".x1i10hfl xjbqb8w x6umtig x1b1mbwd xaqea5y xav7gou x9f619 x1ypdohk xt0psk2 xe8uvvx xdj266r x11i5rnm xat24cr x1mh8g0r xexx8yu x4uap5 x18d9i69 xkhd6sd x16tdsg8 x1hl2dhg xggy1nq x1a2a7pz x1heor9g x1lku1pv"}
(Session info: MicrosoftEdge=107.0.1418.56)
Stacktrace:
Backtrace:
Microsoft::Applications::Events::EventProperties::SetProperty [0x00007FF696738532+9986]
Microsoft::Applications::Events::EventProperty::EventProperty [0x00007FF6966D5D62+1445202]
Ordinal0 [0x00007FF6962BFC8C+654476]
Ordinal0 [0x00007FF6963036C2+931522]
Ordinal0 [0x00007FF696303B10+932624]
Ordinal0 [0x00007FF69633FC17+1178647]
Ordinal0 [0x00007FF696323BDF+1063903]
Ordinal0 [0x00007FF6962F5FF4+876532]
Ordinal0 [0x00007FF69633CF70+1167216]
Ordinal0 [0x00007FF6963239B3+1063347]
Ordinal0 [0x00007FF6962F506A+872554]
Ordinal0 [0x00007FF6962F402E+868398]
Ordinal0 [0x00007FF6962F570F+874255]
Microsoft::Applications::Events::EventProperty::EventProperty [0x00007FF696596108+135416]
Microsoft::Applications::Events::EventProperty::EventProperty [0x00007FF6965802CF+45759]
Microsoft::Applications::Events::EventProperty::EventProperty [0x00007FF69658374C+59196]
Ordinal0 [0x00007FF6963CB1F4+1749492]
Microsoft::Applications::Events::EventProperty::EventProperty [0x00007FF6966DB65A+1467978]
Microsoft::Applications::Events::EventProperty::EventProperty [0x00007FF6966DFEF4+1486564]
Microsoft::Applications::Events::EventProperty::EventProperty [0x00007FF6966E004D+1486909]
Microsoft::Applications::Events::EventProperty::EventProperty [0x00007FF6966E7E0B+1519099]
BaseThreadInitThunk [0x00007FFC227F74B4+20]
RtlUserThreadStart [0x00007FFC236626A1+33]
1条答案
按热度按时间thtygnil1#
它会告诉您错误是什么:
selenium.common.exceptions.NoSuchElementException:消息:没有此元素:找不到元素:{“方法”:“css选择器”,“选择器”:“
确保搜索的是实际存在的元素。