我正試圖為一個房屋租賃網站建立搜刮器,但我在移動到下一頁時失敗了。并顯示以下錯誤:
line 44, in <module> browser. find_element_by_xpath("//div[@class='pagination_hi']/[rel='next']")。 點擊()
這就是分頁數字所在的元素:
這就是分頁數字所在的元素。
<div class="pagination_hi">
前一頁
</div>< div class="pagination_hi">
<a href="https://www.28 hse.com/rent/page-2" rel="next">next_page</a>
uj5u.com熱心網友回復:
正確的XPath語法應該是
//div [@class='pagination_hi']/a[@rel='next']
你也可以嘗試通過鏈接文本來定位節點:
browser.find_element_by_link_text("next_page").click()
uj5u.com熱心網友回復:
在Selenium中,有4種方法可以點擊。
我將使用這個xpath
。//a[text()='next_page'/span>]
代碼試用1 :
time.sleep(5)。
驅動。 find_element_by_xpath("//a[text()='next_page']").click()
代碼試用2 :
WebDriverWait(driver, 20).until(EC. element_to_be_clickable((By. XPATH, "//a[text()='next_page']")).click()
代碼試用3 :
time.sleep(5)
button = driver.find_element_by_xpath("/a[text()='next_page']")
driver.execute_script("arguments[0].click();", button)
代碼試驗4 :
time.sleep(5)
button = driver.find_element_by_xpath("/a[text()='next_page']")
ActionChains(driver).move_to_element(button).click().perform()
匯入 :
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.action_chains import ActionChains
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/309726.html
標籤:
