我想抓取這個 URL 來遍歷頁面并獲取它們的內容。這就是我嘗試過的:
driver.get("https://www.shoroukbookstores.com/books/publishing-house.aspx?id=429c2704-5fa3-43b0-9ad7-c2ec9062beb3")
page_count = 1
while True:
page_count = 1
try:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//*[@id='Body_AspNetPager']/a[%s]" % page_count))).click()
print("Next page clicked")
except NoSuchElementException:
print("No more pages")
break
driver.quit()
我得到了 102 頁中的 10 頁;特別是 URL 中的可見頁碼。如何對這個 URL 中的所有頁面進行分頁?
uj5u.com熱心網友回復:
不要點擊每個數字,而是使用下一個按鈕。
driver.implicitly_wait(5)
driver.get("https://www.shoroukbookstores.com/books/publishing-house.aspx?id=429c2704-5fa3-43b0-9ad7-c2ec9062beb3")
while True:
try:
navigation_links = driver.find_element_by_xpath(f"//*[@id='Body_AspNetPager']").find_elements_by_tag_name("a")
next_page = len(navigation_links) - 1 # next page button is second from behind
driver.find_element_by_xpath(f"//*[@id='Body_AspNetPager']/a[{next_page}]").click()
print("Next page clicked")
except NoSuchElementException:
print("No more pages")
break
driver.quit()
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/391810.html
上一篇:用于鎖定或的C內置或行內匯編
下一篇:如何找到“著作權”文本?
