![](/img/trans.png)
[英]Scraping a website that URL doesn't change when clicking on "next page" button
[英]Scraper doesn't stop clicking on the next page button
我在python中編寫了一個與selenium結合使用的腳本,以便在搜索時顯示一些名稱和相應的地址,搜索關鍵字是“Saskatoon”。 但是,在這種情況下,數據遍歷多個頁面。 除了一件事,我的劇本幾乎可以做所有事情。
這是鏈接: Page_link
Search_keyword: Saskatoon
(在城市/城鎮地區)。
這是我寫的:
from selenium import webdriver; import time
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys
driver = webdriver.Chrome()
wait = WebDriverWait(driver, 10)
driver.get("above_link")
time.sleep(3)
search_input = driver.find_element_by_id("cityField")
search_input.clear()
search_input.send_keys("Saskatoon")
search_input.send_keys(Keys.ENTER)
while True:
try:
wait.until(EC.visibility_of_element_located((By.LINK_TEXT, "›"))).click()
time.sleep(2)
except:
break
driver.quit()
順便說一句,我剛剛從這個腳本中取出了名稱和地址部分,我想這里沒有相關內容。 謝謝。
您可以使用>
按鈕的class
屬性,如在最后一頁上"ng-scope disabled"
"ng-scope"
- 在其余頁面上 - "ng-scope"
:
wait.until(EC.visibility_of_element_located((By.XPATH, "//li[@class='ng-scope']/a[.='›']"))).click()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.