Answer the question
In order to leave comments, you need to log in
How to scroll page up Selenium Python?
Good afternoon everyone. I am writing a Python script that parses the number of publications from this page: https://yandex.ru/chat/#/chats/1%2F0%2Fccb05ef5-14...
But the parser sees only the first 6 publications, you need to scroll the page up. Added a line:
driver.execute_script("window.scrollTo(document.body.scrollHeight, 0);")
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from bs4 import BeautifulSoup
list_with_link = ['https://yandex.ru/chat/#/chats/1%2F0%2Fccb05ef5-1472-4e50-a926-602807a6ef94']
driver = webdriver.Chrome()
driver.implicitly_wait(10)
for url in list_with_link:
driver.get(url)
driver.execute_script("window.scrollTo(document.body.scrollHeight, 0);")
count = 0
html = driver.page_source
soup = BeautifulSoup(html, 'lxml')
count_of_publ = soup.find_all('div', class_='yamb-message-row')
for text in count_of_publ:
count += 1
print('Количество публикаций:', count)
Answer the question
In order to leave comments, you need to log in
General idea. You need to turn the mouse wheel (scroll) through JS.
Put something like this in driver.execute_script :
var evt = document.createEvent('MouseEvents');
evt.initEvent('wheel', true, true);
evt.deltaY = -100000;
document.querySelector('.yamb-conversation__content').dispatchEvent(evt);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question