嗨,我正在嘗試在以下鏈接中與此 Web 元素互動https://www.gurufocus.com/stocks
在這里你可以找到圖片
我想將其設定為 100,以便在我嘗試使用以下代碼與之互動時可視化 100 只股票
wd.find_element_by_xpath("/html/body/div[1]/div/div/div[1]/section[2]/main/div/div[1]/div[3]/div[1]/span/div[2]").click()
wd.find_element_by_xpath("/html/body/div[2]/div[6]").click()
但只有第一行有效,第二行給我以下錯誤
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id='el-popover-2775']"}
(Session info: chrome=106.0.5249.119)
它無法找到它我也嘗試過使用方法 find element_by_id 但仍然無法找到將數字設定為 100 的按鈕這個有沒有人有其他解決方案?提前感謝讓我知道您是否需要更多資訊,我會盡快回答。
uj5u.com熱心網友回復:
您可以像這樣選擇下拉串列:
from selenium.webdriver.common.by import By
driver.find_element(By.CLASS_NAME, "aio-tabs-button").click()
并像這樣選擇 100:
driver.find_element(By.XPATH, "//div[@class='item' and contains(text(), '100')]").click()
但是,我建議使用 API 和請求之類的包,而不是模擬瀏覽器。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/516130.html
