-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path16_selenium_scroll.py
49 lines (34 loc) · 1.37 KB
/
16_selenium_scroll.py
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
41
42
43
44
45
46
47
48
49
# import requests
# from bs4 import BeautifulSoup
# headers = {
# "User-Agent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36",
# "Accept-Language" : "ko-KR,ko"
# }
# url = "https://play.google.com/store/movies/top"
# res = requests.get(url, headers = headers)
# res.raise_for_status()
# soup = BeautifulSoup(res.text, "lxml")
# movies = soup.find_all("div", attrs={"class" : "ImZGtf mpg5gc"})
# for movie in movies :
# title = movie.find("div",attrs = {"class" : "WsMG1c nnK0zc"}).get_text()
# print(title)
# # with open("movie.html", "w", encoding="utf8") as f:
# # # f.write(res.text)
# # f.write(soup.prettify())
from selenium import webdriver
import time
browser = webdriver.Chrome("/Users/jaeyeol/jaeyeol/python/chromedriver")
browser.maximize_window()
url = "https://play.google.com/store/movies/top"
browser.get(url)
# browser.execute_script("window.scrollTo(0,1080)")
# browser.execute_script("window.scrollTo(0,document.body.scrollHeight)")
interval = 2
prev_height = browser.execute_script("return document.body.scrollHeight")
while True:
browser.execute_script("window.scrollTo(0,document.body.scrollHeight)")
time.sleep(interval)
curr_height = browser.execute_script("return document.body.scrollHeight")
if curr_height == prev_height:
break
prev_height = curr_height