-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathselenium_scroll_page_down.py
More file actions
40 lines (30 loc) · 1.1 KB
/
Copy pathselenium_scroll_page_down.py
File metadata and controls
40 lines (30 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from selenium import webdriver
from time import sleep
driver = webdriver.Firefox()
driver.get("https:// ... ")
driver.execute_script("window.scrollTo(0, document.body.scrollHeight)") # scroll down the complete page height or a specific height !!!
time.sleep(3)
driver.close()
# driver.quit()
# or
driver.execute_script("window.scrollTo(0, Y)") # Y is a height , 1080 for example
# or
from selenium.webdriver.common.keys import Keys
html = driver.find_element_by_tag_name('html')
html.send_keys(Keys.END)
# or
label.sendKeys(Keys.PAGE_DOWN)
# to scroll to a page with infinite loading !!!
time_to_sroll = 0.5
# scroll height
last_height = driver.execute_script("return document.body.scrollHeight")
while True:
# scroll down to bottom
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
# Wait to load page
time.sleep(time_to_scroll)
# new scroll height , compare with last scroll height
new_height = driver.execute_script("return document.body.scrollHeight")
if new_height == last_height:
break
last_height = new_height