如何通过Selenium和Python在我的页面上向下滚动?
正在尝试向下滚动到页面底部 但没有结果(没有动作) 我的代码:如何通过Selenium和Python在我的页面上向下滚动?,python,selenium,selenium-webdriver,scroll,webdriverwait,Python,Selenium,Selenium Webdriver,Scroll,Webdriverwait,正在尝试向下滚动到页面底部 但没有结果(没有动作) 我的代码: 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_ele
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
您可以使用
操作移动到底部的版权
类元素。移动到元素
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()
有几种方法可以向下滚动到页面底部。根据url
https://silpo.ua/offers/?categoryId=13
版权信息位于页面底部。因此,您可以使用scrollIntoView()
方法在中滚动版权消息,如下所示:
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)
谢谢你,先生!如何使用选择器“product-list\uuu item-image”持续跳转到所有元素???我可以跳到第一个,但不能跳到下一个。这可能是重复的,因为selenium无法单击不在视口中的链接?我们不应该再这样做了。