我目前正在使用 selenium 從 Sneider Electric 獲取產品資訊,這是目前我收到的錯誤:
selenium.common.exceptions.NoSuchElementException: Message:
no such element: Unable to locate element:
{"method":"xpath","selector":"/html/body/div[2]/main/div[5]/ul/li/div/div/div/div/div/ul/li[1]/div/div/div[2]/div[2]/section/div/product-cards-wrapper//div/ul/li[1]/product-card/article/div/div[1]/product-card-main-info//div/pes-router-link[2]/a/h3"}
目前,我試圖從中提取此資訊的網站是以下 URL:
解決方案
要提取您需要使用的所需文本shadowRoot.querySelector(),您可以使用以下定位器策略:
driver.get("https://www.se.com/us/en/product-range/63426-powerlogic-accusine-pcs+/?N=4176697776&No=0&Nrpp=12")
time.sleep(5)
description = driver.execute_script('''return document.querySelector("product-cards-wrapper.hydrated").shadowRoot.querySelector("product-card.hydrated").shadowRoot.querySelector("product-card-main-info.hydrated").shadowRoot.querySelector("pes-router-link.description.hydrated a > h3")''')
print(description.text)
控制臺輸出:
Active harmonic filter - 60 A 380..480 V AC - IP00 enclosure
參考
您可以在以下位置找到一些相關的詳細討論:
- 如何使用 Selenium 和 Python 在網站 https://www.virustotal.com 中的 shadow-root(打開)中找到名字欄位
- 如何使用 Python 和 Selenium 通過 cookie 協議頁面?
- 無法使用 Selenium 和 Python 在 #shadow-root (open) 中找到 Sign In 元素
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/372565.html
