python webdriver模拟下拉页面
可以使用ActionChains模块来模拟下拉页面的操作,具体代码如下:
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
driver = webdriver.Chrome()
driver.get("https://www.baidu.com")
# 执行一些操作,使页面出现滚动条
# ...
# 模拟下拉操作
actions = ActionChains(driver)
actions.move_to_element(driver.find_element_by_tag_name('body')).click_and_hold().perform()
actions.move_by_offset(0, 100).perform()
actions.release().perform()
其中,move_to_element()方法用于将鼠标移动到指定元素上,这里我们选择了页面的body元素;click_and_hold()方法模拟按下鼠标左键并保持不放;move_by_offset()方法将鼠标向下移动指定距离,这里为100个像素;最后,release()方法模拟释放鼠标左键。
通过多次执行这个操作,可以模拟连续的下拉操作
原文地址: https://www.cveoy.top/t/topic/hu3K 著作权归作者所有。请勿转载和采集!