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")
如果这有帮助,请告诉我!
添加回答
举报