這個在 Python 3 中使用 Selenium 的腳本幫助我通過單擊查看全部按鈕從頁面中抓取資料,但它停止作業,我不知道原因。你能幫我寫代碼嗎?
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
nav= Service(ChromeDriverManager().install())
driver= webdriver.Chrome(service= nav)
driver.get('https://getdaytrends.com/es/venezuela/#moreTrends')
driver.find_element(By.CLASS_NAME,'btn btn-outline-primary px-5')
driver.execute_script("arguments[0].click();", search)
datos= driver.find('table')
回溯是:
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":".btn btn-outline-primary px-5"}
uj5u.com熱心網友回復:
點擊Ver todo 34你需要scrollIntoView()所需的元素和誘導
注意:您必須添加以下匯入:
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
參考
您可以在以下位置找到一些關于NoSuchElementException的相關討論:
- selenium.common.exceptions.NoSuchElementException:訊息:沒有這樣的元素:嘗試使用硒單擊“下一步”按鈕時無法定位元素
- python中的硒:NoSuchElementException:訊息:沒有這樣的元素:無法定位元素
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/362303.html
