Spaces:
Runtime error
Runtime error
| # install dulu: | |
| # pip install google-play-scraper pandas gradio | |
| import os | |
| os.system('pip install google-play-scraper') | |
| from google_play_scraper import reviews_all | |
| import pandas as pd | |
| import gradio as gr | |
| import tempfile | |
| import os | |
| def scrape_reviews(app_id, language, country): | |
| try: | |
| # Ambil semua ulasan | |
| reviews = reviews_all( | |
| app_id, | |
| sleep_milliseconds=0, | |
| lang=language, | |
| country=country | |
| ) | |
| if not reviews: | |
| return None, "Tidak ada ulasan ditemukan." | |
| # Konversi ke DataFrame | |
| df = pd.DataFrame(reviews) | |
| df_filtered = df[['at', 'score', 'content']] | |
| df_filtered.columns = ['Tanggal', 'Rating', 'Ulasan'] | |
| # Simpan sementara ke CSV | |
| temp_dir = tempfile.mkdtemp() | |
| file_path = os.path.join(temp_dir, f"ulasan_{app_id}.csv") | |
| df_filtered.to_csv(file_path, index=False, encoding='utf-8-sig') | |
| return file_path, f"Berhasil mengambil {len(df_filtered)} ulasan." | |
| except Exception as e: | |
| return None, f"Error: {str(e)}" | |
| # Buat UI Gradio | |
| with gr.Blocks() as demo: | |
| gr.Markdown("# 📱 Scraper Ulasan Google Play Store") | |
| gr.Markdown("Masukkan **App ID** Google Play, pilih bahasa dan negara, lalu unduh CSV ulasan.") | |
| with gr.Row(): | |
| app_id_input = gr.Textbox(label="App ID", value="com.ruangguru.livestudents") | |
| lang_input = gr.Textbox(label="Bahasa", value="id") | |
| country_input = gr.Textbox(label="Negara", value="id") | |
| scrape_button = gr.Button("Mulai Scraping") | |
| output_file = gr.File(label="Download CSV", type="filepath") | |
| status_output = gr.Textbox(label="Status", interactive=False) | |
| scrape_button.click( | |
| scrape_reviews, | |
| inputs=[app_id_input, lang_input, country_input], | |
| outputs=[output_file, status_output] | |
| ) | |
| demo.launch() |