3 回答

TA貢獻1744條經驗 獲得超4個贊
我注意到我的網站的頁面是這樣描述的:
https://obamawhitehouse.archives.gov/briefing-room/speeches-and-remarks?term_node_tid_depth=31&page=1
轉到 。因此,我能夠將我的代碼包裝在一個 while 循環中,添加一個計數器,然后執行 .page=473
page={}.format

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"

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")
如果這有幫助,請告訴我!
添加回答
舉報