嗨,我正在尝试用selenium刮电子商务商店'konga.com‘,但是当我试图获得所有具有公共类名的元素时,我会得到'0’响应和一些错误。这是我的密码
from selenium import webdriver
import time
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
url = 'https://www.konga.com/search?search=IPHONES'
service = Service(executable_path="C:/driver/chromedriver_win32/chromedriver.exe")
driver = webdriver.Chrome(service=service)
driver.get(url)
time.sleep(10)
driver.maximize_window()
product_cards = driver.find_elements(By.CLASS_NAME, 'bbe45_3oExY _22339_3gQb9')
time.sleep(10)
print(len(product_cards))以下是我遇到的错误:
DevTools listening on ws://127.0.0.1:56835/devtools/browser/958d5a8b-268b-4699-8d41-fcd315cbb155
0
[12544:708:1027/102731.294:ERROR:gpu_init.cc(521)] Passthrough is not supported, GL is disabled, ANGLE is
[5080:11512:1027/102831.450:ERROR:util.cc(129)] Can't create base directory: C:\Program Files (x86)\Google\GoogleUpdater发布于 2022-10-27 11:56:08
By.CLASS_NAME一次搜索一个类。您要寻找的这个元素有两个类:bbe45_3oExY和_22339_3gQb9。类名由class属性中的空格分隔。
因此,在本例中,可以使用命令driver.find_elements(By.CLASS_NAME, 'bbe45_3oExY')获得所需的结果。
关于错误的问题,有一个帖子here
https://stackoverflow.com/questions/74219798
复制相似问题