Appia의 IT세상

파이썬[Python] 특정 시점 이후의 구글 앱 평점 및 리뷰 크롤링하기 본문

Python/Python 응용

파이썬[Python] 특정 시점 이후의 구글 앱 평점 및 리뷰 크롤링하기

Appia 2023. 7. 4. 06:20
반응형

파이썬[Python] 특정 시점 이후의 구글 앱 평점 및 리뷰 크롤링하기

파이썬[Python] 특정 시점 이후의 구글 앱 평점 및 리뷰 크롤링하기

이전의 구글(Google) 앱의 대한 평점 및 리뷰를 크롤링 하는 방법에 대해서, 포스팅하였고, 이 부분을 토대로 엑셀로 추출하거나, Exe파일 형태로 이러한 추출기를 만드는 방법에 대해서 이야기를 하였습니다. 하지만, 저의 포스팅에서, 다음과 같은 질문사항들을 수령하였습니다. 

엄청 도움되는 글들 잘 보고 있습니다.
특정 날짜 이후의 리뷰만 출력하고 싶으면 어떻게 해야 할까요?

그래서, 이번 포스팅에서는 특정 날짜 이후에 리뷰만 출력하는 방법에 대해서 이야기를 해보도록 하겠습니다. 

파이썬[Python] 구글 앱 평점 및 리뷰 크롤링하기
 

파이썬[Python] 구글 앱 평점 및 리뷰 크롤링하기

파이썬[Python] 구글 앱 평점 및 리뷰 크롤링하기 이전에 다양한 경로로 저에게 많은 부탁을 하신 분들이 있습니다. 그중 한 앱 개발자분께서는 저의 경쟁사 게임의 리뷰에 대해서 크롤링을 요청

appia.tistory.com

먼저, 상기 링크에 있는 코드를 실행할 경우에 다음과 같은 리뷰들을 크롤링할 수 있습니다. 하지만, 이 부분에서 앞 부분을 검토해보면, 2022년 부터, 날짜에 대해서 크롤링해왔다는 것을 알 수 있습니다. 

전체 리뷰 크롤링 결과

그래서, 먼저 년도를 기준으로 선별해서 크롤링 하는 부분에 대해서 이야기를 해보겠습니다. 

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import google_play_scraper as gps


country = 'us'
lang = 'ko'
id = 'com.simplywerx.compass3d'

info = gps.app(id, lang = lang , country = country)

result_a  = gps.reviews_all(
    id,
    sleep_milliseconds=2000,  # defaults to 0
    lang=lang,  # defaults to 'en'
    country=country,  # defaults to 'us'
    sort=gps.Sort.NEWEST,  # defaults to Sort.MOST_RELEVANT
    filter_score_with=None  # defaults to None(means all score)
)


for item in result_a:
    if item['at'].year >= 2023  :
        print(str(item['at'])+'\t'+item['userName']+'\t'+str(item['score'])+'\t'+item['content'])

저의 경우 위에서 보이는 부분가 같이 크롤링하는 부분은 동일하게 전체를 크롤링하지만, 출력시점에서 원하는 정보만 선별할 수 있게 년도만 구별하였습니다. 

2023년 리뷰만 크롤링하기

이번에는 23년 5월 이후에 포스팅만 출력해보도록 하겠습니다. 

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import google_play_scraper as gps


country = 'us'
lang = 'ko'
id = 'com.simplywerx.compass3d'

info = gps.app(id, lang = lang , country = country)

result_a  = gps.reviews_all(
    id,
    sleep_milliseconds=2000,  # defaults to 0
    lang=lang,  # defaults to 'en'
    country=country,  # defaults to 'us'
    sort=gps.Sort.NEWEST,  # defaults to Sort.MOST_RELEVANT
    filter_score_with=None  # defaults to None(means all score)
)


for item in result_a:
    if item['at'].year >= 2023 and item['at'].month >= 5 :
        print(str(item['at'])+'\t'+item['userName']+'\t'+str(item['score'])+'\t'+item['content'])

위의 코드를 실행하면 다음과 같이 23년 5월 이후에 값만 출력을 해줍니다. 

2023년 5월 이후 포스팅

여기에서 한가지 문제점이 있다면, 바로 2022년 3월 이후 리뷰를 크롤링하고자 합니다. 이럴 경우에, 흔한 오류로 인하여 다음과 같이 코드를 작성할 것입니다. 

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import google_play_scraper as gps


country = 'us'
lang = 'ko'
id = 'com.simplywerx.compass3d'

info = gps.app(id, lang = lang , country = country)

result_a  = gps.reviews_all(
    id,
    sleep_milliseconds=2000,  # defaults to 0
    lang=lang,  # defaults to 'en'
    country=country,  # defaults to 'us'
    sort=gps.Sort.NEWEST,  # defaults to Sort.MOST_RELEVANT
    filter_score_with=None  # defaults to None(means all score)
)


for item in result_a:
    if item['at'].year >= 2022 and item['at'].month >= 3  :
        print(str(item['at'])+'\t'+item['userName']+'\t'+str(item['score'])+'\t'+item['content'])

그럼 다음과 같은 출력이 나타나는 것을 알 수 있습니다. 

2022년 구글 리뷰 크롤링(오류 발생)

위에서 보는 바와 같이 1월 2월의 리뷰가 없는 것을 알 수 있습니다. 바로, 여기에는 약간의 오류가 있었기 때문입니다. 

바로 위의 조건문에서 2022년 / 3월 기준을 And 처리되었습니다. 이럴 경우 2023 년 1월 , 2월은 해당이 안 되기 때문에 이 부분에 문제가 발생하였습니다. 그래서 코드를 다음과 같이 수정하였습니다. 

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import google_play_scraper as gps


country = 'us'
lang = 'ko'
id = 'com.simplywerx.compass3d'

info = gps.app(id, lang = lang , country = country)

result_a  = gps.reviews_all(
    id,
    sleep_milliseconds=2000,  # defaults to 0
    lang=lang,  # defaults to 'en'
    country=country,  # defaults to 'us'
    sort=gps.Sort.NEWEST,  # defaults to Sort.MOST_RELEVANT
    filter_score_with=None  # defaults to None(means all score)
)


for item in result_a:
	# 조건물 수정 완료
    if (item['at'].year >= 2022 and item['at'].month >= 3) or (item['at'].year == 2023)  :
        print(str(item['at'])+'\t'+item['userName']+'\t'+str(item['score'])+'\t'+item['content'])

그럼 다음과 같이 나타나는 것을 알 수 있습니다. 

2022년 3월 이후 리뷰 크롤링

이와 같은 방법으로 day 기준으로 특정 날 이후도 크롤링이 가능합니다. 이 부분은 위에 부분을 활용하여 직접 가능할 것으로 보입니다. (여러분에게 직접할 수 있는 기회를 드려보겠습니다.) 

파이썬[Python] 구글 앱 리뷰 실행파일 형태로 엑셀 추출기 만들기

 

파이썬[Python] 구글 앱 리뷰 실행파일 형태로 엑셀 추출기 만들기

파이썬[Python] 구글 리뷰 실행파일 형태로 엑셀 추출기 만들기 이전 포스팅에서 구글의 앱 리뷰에 대해서 엑셀로 추출하는 방법에 대해서 포스팅을 해봤습니다. 여기에서 가장 쉬운 질문을 하나

appia.tistory.com

이번 포스팅에서는 파이썬[Python] 특정 시점 이후의 구글 앱 평점 및 리뷰 크롤링하기라는 주제로 포스팅을 해봤습니다. 실제, 많은 사람들이 이 부분을 바탕으로 원하는 리뷰들을 크롤링할 수 있을 것입니다. 저의 경우에는 이전에 크몽등에서 이 부분을 활용한 기억이 있습니다. 여러분들도 원하시는 부분에서 잘 활용하시길 기원합니다. 혹 궁금하신 점이나 문의 사항이 있으시면 언제든지 댓글 및 방명록에 글 남겨주시길 바랍니다. 

반응형
Comments