-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path17_headless_chrome.py
More file actions
72 lines (52 loc) · 1.99 KB
/
17_headless_chrome.py
File metadata and controls
72 lines (52 loc) · 1.99 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
from selenium import webdriver
options = webdriver.ChromeOptions()
options.headless = True
options.add_argument("window-size=1920x1080")
browser = webdriver.Chrome(options=options)
browser.maximize_window()
# 페이지 이동
url = "https://play.google.com/store/movies/top"
browser.get(url)
import time
interval = 2 # 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
print("스크롤 완료")
browser.get_screenshot_as_file("google_movie.png")
import requests
from bs4 import BeautifulSoup
soup = BeautifulSoup(browser.page_source, "lxml")
# movies = soup.find_all("div", attrs={"class":["ImZGtf mpg5gc", "Vpfmgd"]})
movies = soup.find_all("div", attrs={"class":"Vpfmgd"})
print(len(movies))
for movie in movies:
title = movie.find("div", attrs={"class":"WsMG1c nnK0zc"}).get_text()
# 할인 전 가격
original_price = movie.find("span", attrs={"class":"SUZt4c djCuy"})
if original_price:
original_price = original_price.get_text()
else:
#print(title, " <할인되지 않은 영화 제외>")
continue
# 할인된 가격
price = movie.find("span", attrs={"class":"VfPpfd ZdBevf i5DZme"}).get_text()
# 링크
link = movie.find("a", attrs={"class":"JC71ub"})["href"]
# 올바른 링크 : https://play.google.com + link
print(f"제목 : {title}")
print(f"할인 전 금액 : {original_price}")
print(f"할인 후 금액 : {price}")
print(f"링크 : ", "https://play.google.com" + link)
print("-" * 100)
browser.quit()