簡體   English   中英

當我嘗試使用 selenium 抓取該站點時,為什么會得到“0”響應和一些錯誤?

[英]Why do I get '0' response and some error when I try to scrape this site with selenium?

您好,我正在嘗試使用 selenium 抓取電子商務商店“konga.com”,但是當我嘗試獲取具有通用名稱 class 的所有元素時,我得到“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

By.CLASS_NAME搜索一個 class。 您正在尋找的這個元素有兩個類: bbe45_3oExY_22339_3gQb9 Class 名稱在class屬性中由空格分隔。
所以在這種情況下,您可以使用命令driver.find_elements(By.CLASS_NAME, 'bbe45_3oExY')獲得您想要的結果

關於錯誤的問題,這里有一個帖子

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM