如何通过Selenium和Python在页面上向下滚动?

时间:2018-12-01 13:40:17

标签: python selenium selenium-webdriver scroll webdriverwait

尝试向下滚动到页面底部 https://silpo.ua/offers/?categoryId=13 但没有结果(没有动静)

我的代码:

import bs4
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time

URL = "https://silpo.ua/offers/?categoryId=13"
driver = webdriver.Firefox()
driver.get(URL)

page = driver.find_element_by_tag_name("html")
page.send_keys(Keys.PAGE_DOWN)

html = driver.page_source

1 个答案:

答案 0 :(得分:2)

您可以使用copyright移至底部的actions.move_to_element类元素

from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains

url ="https://silpo.ua/offers/?categoryId=13"
driver = webdriver.Chrome()
driver.get(url)
element = driver.find_element_by_css_selector(".copyrights")
actions = ActionChains(driver)
actions.move_to_element(element).perform()

您可以对此进行更改,例如说您想使用最后一种产品:

element = driver.find_elements_by_css_selector(".product-list__item-content")[-1]
actions = ActionChains(driver)
actions.move_to_element(element).perform()