Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- CH01
- Perceptron Convergence theorem
- 알고리즘
- 델타 rule
- 개발순서
- graphical models
- Numerical optimization
- 5397번
- 로지스틱 회귀
- 선형분류
- 인공지능
- 자바ORM표준JPA프로그래밍
- MySQL
- 근구하기
- SCPC
- 스터디
- vector미분
- Fisher discriminant analysis
- 2018
- chapter01
- undirected graphical model
- falsePosition
- secant
- bisection
- directed graphical model
- 이것이 MySQL이다
- 알고리즘대회
- 선형판별분석
- chapter02
- 1차예선
Archives
- Today
- Total
computer_study
[크롤링] python 사용하여 플레이스토어 리뷰 크롤링하기(selenium) 본문
이글은 아래 링크를 참고하여 작성하였습니다.
https://signing.tistory.com/93
[리뷰 크롤링] PlayStore 댓글 크롤링하기 in python 5(feat. selenium)
[리뷰 크롤링] PlayStore 댓글 크롤링하기 in python 1(feat. selenium) [리뷰 크롤링] PlayStore 댓글 크롤링하기 in python 2(feat. selenium) [리뷰 크롤링] PlayStore 댓글 크롤링하기 in python 3(feat. sele..
signing.tistory.com
1. Selenium이란?

셀레늄은 웹 브라우저의 자동화를 가능하게 하는 프레임워크이다.
브라우저와의 사용자 간의 상호 작용을 테스트하는 확장 기능, 브라우저 할당 확장을 위한 배포 서버, 모든 주요 웹 브라우저에 적용 가능한 코드를 작성할 수 있는 W3C WebDriver 사양 구현을 위한 인프라를 제공한다.
2. Selenium 장단점
장점
- 오픈소스이기에 라이센스 비용이 없다.
- Java, Ruby, Perl, PHP, Python 과 같은 여러 프로그래밍 및 스크립팅 언어를 지원한다.
- Safari, Chrome, IE, Mozilla, Opera 등 다양한 브라우저에서 사용할 수 있다.
단점
- 모바일보단 웹 어플리케이션에 적합하다.
- 오픈소스 도구이기에 기술적 지원이 없다.
3. Selenium 대체
- Katalon Studio
- Subject7
- SCREENSTER
- testcraft
- endtest
- Browsersync
- Protractor
- Casper.js
- Ghost Inspector
- cypress
- phantomJS
다양한 대안 서비스들이 있다. 각 서비스에 대한 특징은 아래 링크에서 확인 가능하다.
https://ko.myservername.com/top-10-best-selenium-alternatives-you-should-try
시도해야 할 최고의 10 가지 셀레늄 대안 - 다른
이 튜토리얼에서는 각각의 기능, 사양 및 가격 정보와 함께 무료 및 상업용 Selenium 대안을 나열했습니다.
ko.myservername.com
4. 크롤링 코드
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import time
options = Options()
options.add_argument('--kiosk') # 화면을 전체화면으로 열어주기 위해서
# 크롤링하고자 하는 리뷰 페이지의 url을 적어준다.
url = "https://play.google.com/store/apps/details?id=com.truefriend.neosmarta&showAllReviews=true" # 한투 url
driverPath = "C:/Users/User/Downloads/chromedriver_win32/chromedriver.exe" # Chrome Driver path
driver = webdriver.Chrome(driverPath, options=options) # Open Chrome
driver.get(url) # Enter the url
SCROLL_PAUSE_TIME = 2
SCROLL_TIMES = 4 # 4번 스크롤 후 더보기 버튼 생성되기에 4
CLICK_PAUSE_TIME = 2
file_name = 'reviews/mts_review.txt'
last_height = driver.execute_script("return document.body.scrollHeight")
# 스크롤 가장 아래까지 내리기 ([더보기] 누르면서)
while True:
for i in range(SCROLL_TIMES):
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
time.sleep(SCROLL_PAUSE_TIME) # 에러없이 크롤링을 위해
# 중간중간 [전체 리뷰] 버튼 누르기
spread_review = driver.find_elements_by_xpath("//button[@jsaction='click:TiglPc']")
for i in range(len(spread_review)):
isTrue = spread_review[i].is_displayed()
if isTrue:
driver.execute_script("arguments[0].click()", spread_review[i])
time.sleep(CLICK_PAUSE_TIME)
more_button = driver.find_elements_by_xpath("//span[@class='RveJvd snByac']")
# [전체 리뷰] 버튼이 있다면 눌러준다.
if more_button:
more_button[0].click()
# 더이상 내려가는 곳이 없으면 break
new_height = driver.execute_script("return document.body.scrollHeight")
if new_height == last_height:
break
last_height = new_height
# [전체 리뷰]버튼을 누르면 jsname이 달라지기에 긴글과 짧은 글을 따로 긁는다
reviews = []
short_reviews = driver.find_elements_by_xpath("//span[@jsname='bN97Pc']")
for i in range(len(short_reviews)):
reviews.append(short_reviews[i].text)
long_reviews = driver.find_elements_by_xpath("//span[@jsname='fbQN7e']")
for i in range(len(long_reviews)):
reviews.append(long_reviews[i].text)
# txt 파일에 글 쓰기
cnt = 0
with open(file_name, 'w', encoding='utf-8') as f:
for review in reviews:
if review:
cnt += 1
f.write(review)
'기타' 카테고리의 다른 글
[ Word Cloud ] 파이썬으로 Word Cloud 사용하기 (3) | 2020.07.20 |
---|