本文介绍了如何通过Selenium和Python在页面上向下滚动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
尝试向下滚动到页面底部 https://silpo.ua/offers/?categoryId=13 但没有结果(没有动静)
Trying to scroll down to the bottom of the pagehttps://silpo.ua/offers/?categoryId=13but there is no result (no movements)
我的代码:
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
推荐答案
有几种方法可以向下滚动到页面底部.根据网址https://silpo.ua/offers/?categoryId=13
,版权消息位于页面底部.因此,您可以使用scrollIntoView()
方法在视口如下:
There are several approaches to scroll down to the bottom of the page. As per the url https://silpo.ua/offers/?categoryId=13
the copyright message is located at the bottom of the page. So you can use scrollIntoView()
method to scroll the copyright message within the Viewport as follows:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
URL = "https://silpo.ua/offers/?categoryId=13"
driver = webdriver.Firefox(executable_path=r'C:\WebDrivers\geckodriver.exe')
driver.get(URL)
copyright = WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "div.copyrights")))
driver.execute_script("return arguments[0].scrollIntoView(true);", copyright)
这篇关于如何通过Selenium和Python在页面上向下滚动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!