亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

硒蟒蛇 - 執行操作,單擊下一頁,重復直到最后一頁

硒蟒蛇 - 執行操作,單擊下一頁,重復直到最后一頁

哈士奇WWW 2022-09-13 19:37:53
我正在嘗試對網頁執行操作,單擊“下一步”按鈕,然后重復該操作,直到到達最后一頁。我嘗試過在堆棧溢出上使用類似問題的答案,但我無法讓它們正常工作?,F在唯一發生的事情是網頁打開。我的代碼都沒有發生, 用網頁做事.我的代碼在下面。感謝您的幫助!從硒導入網絡驅動程序從 webdriver_manager.chrome 導入 Chrome驅動程序管理器driver = webdriver.Chrome(ChromeDriverManager().install())driver.get('https://obamawhitehouse.archives.gov/briefing-room/speeches-and-remarks')while True:    next_page_btn = driver.find_elements_by_xpath("//li[@class = 'pagination-next']/a")    if len(next_page_btn) < 1:        print("No more pages left")        break    else:        <MY CODE>        WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.LINK_TEXT, 'Next'))).click() 
查看完整描述

3 回答

?
慕無忌1623718

TA貢獻1744條經驗 獲得超4個贊

我注意到我的網站的頁面是這樣描述的:

https://obamawhitehouse.archives.gov/briefing-room/speeches-and-remarks?term_node_tid_depth=31&page=1

轉到 。因此,我能夠將我的代碼包裝在一個 while 循環中,添加一個計數器,然后執行 .page=473page={}.format


查看完整回答
反對 回復 2022-09-13
?
烙印99

TA貢獻1829條經驗 獲得超13個贊

請檢查以下解決方案供您參考:


from selenium import webdriver

from selenium.webdriver.common.by import By

from selenium.webdriver.support import expected_conditions as EC

from selenium.webdriver.support.ui import WebDriverWait as Wait

from selenium.webdriver.support.ui import WebDriverWait

from selenium.common.exceptions import TimeoutException



driver = webdriver.Chrome(executable_path=r"\chromedriver.exe")


driver.get('https://obamawhitehouse.archives.gov/briefing-room/speeches-and-remarks')

wait = WebDriverWait(driver,30)


flag = True


while flag:

 try:

    element = wait.until(EC.element_to_be_clickable((By.XPATH, "//a[contains(text(),'Next')]")))

    if (element != 0):

        element.click()


 except TimeoutException as ex:

        print "It is all good, no element there"


查看完整回答
反對 回復 2022-09-13
?
慕妹3242003

TA貢獻1824條經驗 獲得超6個贊

我看了一下這個網站,似乎分頁的下一個類并不存在。相反,您要查找的“下一步”按鈕具有類尋呼機 - 下一個最后一個

我建議然后改變這一點:

next_page_btn = driver.find_elements_by_xpath("*//li[@class = 'pagination-next']/a")

為此:

next_page_btn = driver.find_elements_by_xpath("*//li[@class = 'pager-next last']/a")

如果這有幫助,請告訴我!


查看完整回答
反對 回復 2022-09-13
  • 3 回答
  • 0 關注
  • 119 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號