본문 바로가기
Study/Python

[Python] ChatGPT 앱 Appstore, Google Playstore 리뷰 크롤링(App ID 확인하기)

by jizy 2024. 12. 19.
728x90

 

 

 

01. Appstore 리뷰 가져오기

1. app_store_scraper 설치하기

!pip install app_store_scraper

 

 

 

2. 리뷰 크롤링

from app_store_scraper import AppStore

# 1. AppStore Review
def extract_appstore_reviews(app_name: str, app_id: int):
    app = AppStore(country='us', app_name=app_name, app_id=app_id) # country='kr': 한국
    app.review()
    app_reviews = pd.DataFrame(app.reviews)

    if 'date' not in app_reviews.columns:
        app_reviews['date'] = None  # 'date' 기본값 None 설정
    else:
        app_reviews['date'] = pd.to_datetime(app_reviews['date'], errors='coerce')

    app_reviews = app_reviews.sort_values('date', ascending=False, na_position='last').reset_index(drop=True)
    app_reviews['app_name'] = app_name
    return app_reviews
    
chatgpt_info = {'chatgpt': 6448311069} # app name, id 설정 
chatgpt_appstore_reviews = pd.DataFrame()
for app_name, app_id in tqdm(chatgpt_info.items()):
    reviews = extract_appstore_reviews(app_name, app_id)
    chatgpt_appstore_reviews = pd.concat([chatgpt_appstore_reviews, reviews], axis=0)

print('Crawling Done..')

file_path = "chatgpt_appstore_reviews.csv" # 파일명 설정
chatgpt_appstore_reviews.to_csv(file_path, index=False, encoding='utf-8-sig')

 

국내 리뷰 결과를 확인하고 싶으면 country 파라미터값을 수정하면 된다.

 

 

 

3. 결과 확인

chatgpt_appstore_reviews.head(3)

 

 

 

 

 

02. Google Playstore 리뷰 가져오기

1. goole-play-scraper 설치하기

pip install google-play-scraper

 

 

✅ 나는 설치해도 오류가 나서 아래 코드로 upgrade를 실행했다.

pip install --upgrade google-play-scraper

 

 

 

2. 리뷰 크롤링

from google_play_scraper import reviews, Sort

# 2. Google PlayStore Review
def extract_playstore_reviews(app_id, lang='en', country='us', num_reviews=100): # lang='ko': 한글, country='kr': 한국
    all_reviews_data = []

    result, _ = reviews(
        app_id,
        lang=lang,
        country=country,
        sort=Sort.NEWEST, # 최신순 정렬
        count=num_reviews
    )
    all_reviews_data.extend(result)
    app_reviews_df = pd.DataFrame(data=all_reviews_data)
    return app_reviews_df
    
app_id = "com.openai.chatgpt" # app id 설정
chatgpt_playstore_reviews = extract_playstore_reviews(app_id, lang='en', country='us', num_reviews=500)

file_path = "chatgpt_playstore_reviews.csv"
chatgpt_playstore_reviews.to_csv(file_path, index=False, encoding='utf-8-sig')

 

국내 리뷰 결과를 확인하고 싶으면 lang, country 파라미터값을 수정하면 된다.

 

 

 

3. 결과 확인

chatgpt_playstore_reviews.head(3)

 

 

 

 

 

03. 리뷰 통합

1. 필요한 columns 선택, column명 통일하기

import pandas as pd
import numpy as np

chatgpt_appstore_reviews_df = pd.read_csv("chatgpt_appstore_reviews.csv", encoding='utf-8-sig')
chatgpt_playstore_reviews_df = pd.read_csv("chatgpt_playstore_reviews.csv", encoding='utf-8-sig')

appstore_selected = chatgpt_appstore_reviews_df[['date', 'review', 'rating', 'userName']]
appstore_selected['source'] = 'appstore'

chatgpt_playstore_reviews_df = chatgpt_playstore_reviews_df.rename(
    columns={
        'content': 'review',  # 리뷰 내용
        'score': 'rating',    # 평점
        'at': 'date',         # 날짜
    }
)
playstore_selected = chatgpt_playstore_reviews_df[['date', 'review', 'rating', 'userName']]
playstore_selected['source'] = 'playstore'

 

 

 

2. 리뷰 통합

reviews_df = pd.concat([appstore_selected, playstore_selected], axis=0, ignore_index=True)
reviews_df.to_csv("chatgpt_combined_reviews.csv", index=False, encoding='utf-8-sig')
reviews_df.head(3)

 

 

 

 

 


 

 

 

 

 

+ App ID 확인하기

1. Appstore 앱 상세 페이지 링크에서 id## 가져오기

드래그된 부분 가져오기

 

 

 

2. Google Playstore 앱 상세 페이지 링크에서 id=com.##.##& 가져오기

드래그된 부분 가져오기

 

 

 

 

 


 

 

📌 참고. 

https://wooing-man.github.io/data%20collection/data_collection1/

 

[App store scraper] 앱스토어 리뷰 수집하기

App store review scraping

wooing-man.github.io

 

https://simbbo-blog.tistory.com/190

 

[끄적이기1] 구글 플레이스토어, 앱스토어 리뷰정보 크롤링 해보기

데이터 크롤링, 스크랩하기 뭐 암튼 데이터 가지고오기. 한 3년전에 처음으로 파이썬 문법이 뭔지도 모를때 동료직원에게 밥사주면서 배웠었다.(실버맨님 감사합니다)그 후에는 지피티 선생님

simbbo-blog.tistory.com

 

728x90