You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Python获取Google Play社交类Top10应用信息并导出CSV的问题(SerpAPI结果不符合预期)

使用Python获取Google Play社交类Top10应用信息并导出CSV的问题(SerpAPI结果不符合预期)

I see you’re having trouble getting accurate Top 10 social app data from Google Play using SerpAPI—your current results don’t match the official charts, have duplicates, and apps aren’t in the right order. Let’s fix this step by step!

The Root Cause

Your current code pulls organic search results from SerpAPI, which aren’t the same as Google’s official Top Charts. Organic results can include sponsored apps, related searches, or non-chart entries. To get the actual ordered top apps, you need to target Google Play’s official charts endpoint directly via SerpAPI parameters.

Corrected Solution

We’ll adjust your parameters to fetch the official Top Free Social Apps (you can switch to other chart types if needed) and extract data from the dedicated charts section in the results. This will give you the correct order, no duplicates, and the exact Top 10 you’re looking for.

Here’s the updated code:

import os
import pandas as pd
from serpapi import GoogleSearch
from dotenv import load_dotenv

# Load API key from .env file
load_dotenv()

# Updated parameters to target official Top Charts
params = {
    "engine": "google_play",
    "apps_category": "SOCIAL",
    "chart": "top_free",  # Critical: fetches official top free apps in the category
    "api_key": os.getenv("API_KEY"),
    "gl": "ua"  # Keep Ukraine as the target region
}

# Fetch results from SerpAPI
search = GoogleSearch(params)
results = search.get_dict()

# Extract data from the official charts section
chart_data = []
# Iterate through charts (usually one entry for the top free social list)
for chart_section in results.get("charts", []):
    # Get top 10 apps from the chart items
    for app in chart_section.get("items", [])[:10]:
        chart_data.append({
            'Title': app.get('title'),
            'Rating': app.get('rating'),
            'Installs': app.get('downloads'),
            'Link': app.get('link')
        })

# Convert to DataFrame, remove duplicates (just in case) and keep top 10
df = pd.DataFrame(chart_data).drop_duplicates(subset=['Title']).head(10)

# Print the clean results
print(df.to_string(index=False))

# Export to CSV (optional but useful)
df.to_csv("google_play_top10_social_ua.csv", index=False, encoding='utf-8-sig')

Key Changes Explained

  1. Added chart: "top_free": This tells SerpAPI to pull Google’s official Top Free Apps list for the SOCIAL category in Ukraine. If you need Top Paid or Top Grossing apps, use "top_paid" or "top_grossing" instead.
  2. Extracted from charts instead of organic_results: The charts section in SerpAPI’s response contains the ordered official chart data, not random organic entries.
  3. Limited to Top 10: We slice the items list to [:10] and use head(10) to ensure we only get the first 10 apps.
  4. Removed Duplicates: The drop_duplicates call fixes any accidental duplicate entries you were seeing (like Cheelee appearing twice in your original results).
  5. CSV Export: Added a line to save the data to a CSV file with proper UTF-8 encoding (so app titles with special characters display correctly).

Expected Outcome

After running this code, you’ll get results that match Google Play’s official Top 10 Social Apps for Ukraine, with apps in the correct order (TikTok should be in its proper chart position) and no duplicates.

内容来源于stack exchange

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.07 10:22:58