[英]Scrap ASIN on amazon webpage product
首先,對不起我糟糕的英語。 實際上,我制作了一個在亞馬遜網頁上查找數據的腳本。 我需要使用 python 和 selenium 在亞馬遜網頁上廢棄 asin。 我已經制作了這個代碼來廢棄asin:
firstResult = driver.find_element_by_css_selector('div[data-index="1"]>div')
asin = firstResult.get_attribute('data-asin')
但它不起作用,我對結果有一些錯誤:
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"div[data-index="1"]>div"}
(Session info: headless chrome=96.0.4664.45)
任何人都知道如何使用 selenium 廢棄 python 中的這個 ASIN 嗎? 泰來幫忙!
您可以等待並查找位於該標簽旁邊的跨度。
wait=WebDriverWait(driver, 60)
driver.get('https://www.amazon.fr/PlayStation-%C3%89dition-Standard-DualSense-Couleur/dp/B08H93ZRK9')
elem=wait.until(EC.presence_of_element_located((By.XPATH," //span[@class='a-list-item' and contains (.,'ASIN')]//span[2]")))
print(elem.text)
進口:
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
輸出:
B08H93ZRK9
另一件事是 url 最后實際上具有相同的值。 可以得到哪個driver.current_url的簡單字符串操作,
https://www.amazon.fr/PlayStation-%C3%89dition-Standard-DualSense-Couleur/dp/ B08H93ZRK9
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.