我正在试图为一个房屋租赁网站建立刮刀,但我在移动到下一页失败。并显示以下错误:
line 44, in <module> browser.find_element_by_xpath("//div[@class='pagination_hi']/[rel='next']").click()这是分页数在其中的元素:
<div class="pagination_hi">
previous_page
</div><div class="pagination_hi">
<a href="https://www.28hse.com/rent/page-2" rel="next">next_page</a>发布于 2021-09-16 18:34:09
Selenium中有4种单击方式。
我将使用这个xpath
//a[text()='next_page']代码试用1 :
time.sleep(5)
browser.find_element_by_xpath("//a[text()='next_page']").click()代码试用2 :
WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.XPATH, "//a[text()='next_page']"))).click()代码试用3 :
time.sleep(5)
button = browser.find_element_by_xpath("//a[text()='next_page']")
browser.execute_script("arguments[0].click();", button)代码试用4 :
time.sleep(5)
button = browser.find_element_by_xpath("//a[text()='next_page']")
ActionChains(browser).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发布于 2021-09-16 13:41:13
正确的XPath语法应该是
//div[@class='pagination_hi']/a[@rel='next']还可以尝试按链接文本定位节点:
browser.find_element_by_link_text("next_page").click()https://stackoverflow.com/questions/69209393
复制相似问题