Skip to content
Advertisements

Python Selenium Scroll Down

from selenium import webdriver
import time

# open firefox
browser = webdriver.Firefox()          
browser.get("https://www.google.com.tr/")     
time.sleep(1)                       

# search input field
search = browser.find_element_by_xpath("//*[@id='tsf']/div[2]/div/div[1]/div/div[1]/input") 
search.send_keys("javascript")
time.sleep(1)                       

# search button
search_button = browser.find_element_by_xpath("//*[@id='tsf']/div[2]/div/div[2]/div[2]/div[2]/center/input[1]")
search_button.submit()
time.sleep(3)                       

# scroll
scrollCounter = 0
while scrollCounter <= 5:
    browser.execute_script("window.scrollTo(0, document.body.scrollHeight);")
    scrollCounter += 1
    time.sleep(1)

# close firefox
browser.close()
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: