如何访问所有国家的android play商店?

zfciruhq  于 2022-11-03  发布在  Android
关注(0)|答案(2)|浏览(624)

我正在做宏提取Android应用程序信息从Google Play商店。我的客户端需要所有的Android应用程序的详细信息在世界上。我留在印度,因为我不能访问其他国家的应用程序。
请帮助我访问所有国家的Google Play应用程序。
我在用 selenium 来刮痧。

46qrfjad

46qrfjad1#

通过在互联网上搜索您的问题,我发现你可以访问其他国家的Google Play商店与VPN应用程序.
通过检查此page,您将看到如何执行此操作的基本说明。
您也可以在SO question中尝试该解决方案,只需在URL中添加参数gl=(countrycode)即可。
例如:https://play.google.com/store/apps/category/BUSINESS/collection/topselling_free
通过添加gl=ru,可以得到俄罗斯的play存储:

https://play.google.com/store/apps/category/BUSINESS/collection/topselling_free?gl=ru
falq053o

falq053o2#

Google Play最近改变了用户界面和链接的结构以及信息的显示,我最近写了一个Scrape Google Play Search Apps in Python博客,在那里我用更多的数据详细描述了整个过程。
要访问所有的countries,需要将country_code传递给'gl'参数。
例如,我从列表中选择了3个国家/地区来展示我的脚本如何工作:

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from parsel import Selector
import time, json

countries = [
    {
        "country_code": "us",
        "country_name": "United States"
    },
    {
        "country_code": "uk",
        "country_name": "United Kingdom"
    },
    {
        "country_code": "ua",
        "country_name": "Ukraine"
    }
]

对于每个country,生成单独的请求:

for country in countries:
    params = {
        'hl': 'en_GB',                  # language 
        'gl': country['country_code'],  # country of the search
    }

    URL = f"https://play.google.com/store/apps?hl={params['hl']}&gl={params['gl']}"

    service = Service(ChromeDriverManager().install())

    options = webdriver.ChromeOptions()
    options.add_argument("--headless")
    options.add_argument("--lang=en")
    options.add_argument("user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36")
    options.add_argument("--no-sandbox")
    options.add_argument("--disable-dev-shm-usage")

    driver = webdriver.Chrome(service=service, options=options)

    driver.get(URL)

之后,还有一个滚动页面获取所有应用的过程:

while True:
    try:
        driver.execute_script("document.querySelector('.snByac').click();")
        time.sleep(2)
        break
    except:
        driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
        time.sleep(2)

使用parcel library提取数据:

selector = Selector(driver.page_source)
driver.quit()

data = {
    'country': country['country_name'],
    'apps': []
}

for app in selector.css('.UVEnyf'):
    title = app.css('.Epkrse::text').get()
    link = 'https://play.google.com' + app.css('.Si6A0c::attr(href)').get()
    rating = app.css('.LrNMN::text').get()
    rating = float(rating) if rating else rating
    thumbnail = app.css('.Q8CSx::attr(srcset)').get().replace(' 2x', '')

    data['apps'].append({
        'title': title,
        'link': link,
        'rating': rating,
        'thumbnail': thumbnail,
    })

google_play_apps.append(data)

在线IDE中的代码和完整示例。
输出量:

[
  {
    "country": "United States",
    "apps": [
      {
        "title": "WhatsApp Messenger",
        "link": "https://play.google.com/store/apps/details?id=com.whatsapp",
        "rating": 4.3,
        "thumbnail": "https://play-lh.googleusercontent.com/bYtqbOcTYOlgc6gqZ2rwb8lptHuwlNE75zYJu6Bn076-hTmvd96HH-6v7S0YUAAJXoJN=s512-rw"
      },
      {
        "title": "TikTok",
        "link": "https://play.google.com/store/apps/details?id=com.zhiliaoapp.musically",
        "rating": 4.4,
        "thumbnail": "https://play-lh.googleusercontent.com/OS-MhSWOPtlUZLt0_UP5TI4juSf0XhyHxGfJa6pA-UIYkZ1BB6QHTZwaMEzZDPqYsmk=s512-rw"
      },
      {
        "title": "Gmail",
        "link": "https://play.google.com/store/apps/details?id=com.google.android.gm",
        "rating": 4.2,
        "thumbnail": "https://play-lh.googleusercontent.com/KSuaRLiI_FlDP8cM4MzJ23ml3og5Hxb9AapaGTMZ2GgR103mvJ3AAnoOFz1yheeQBBI=s512-rw"
      },
      ... other apps
    ]
  },
  {
    "country": "United Kingdom",
    "apps": [
      {
        "title": "WhatsApp Messenger",
        "link": "https://play.google.com/store/apps/details?id=com.whatsapp",
        "rating": 4.3,
        "thumbnail": "https://play-lh.googleusercontent.com/bYtqbOcTYOlgc6gqZ2rwb8lptHuwlNE75zYJu6Bn076-hTmvd96HH-6v7S0YUAAJXoJN=s512-rw"
      },
      {
        "title": "TikTok: Videos, Music & LIVE",
        "link": "https://play.google.com/store/apps/details?id=com.zhiliaoapp.musically",
        "rating": 4.4,
        "thumbnail": "https://play-lh.googleusercontent.com/DkTxmSymkcxHiady0xd_JsIxLLg0f1ducCtMTpO8El-kTW7VF1gCC6ZzhgTgTGwEqqI=s512-rw"
      },
      {
        "title": "Instagram",
        "link": "https://play.google.com/store/apps/details?id=com.instagram.android",
        "rating": 3.7,
        "thumbnail": "https://play-lh.googleusercontent.com/VRMWkE5p3CkWhJs6nv-9ZsLAs1QOg5ob1_3qg-rckwYW7yp1fMrYZqnEFpk0IoVP4LM=s512-rw"
      },
      ... other apps
    ]
  },
  {
    "country": "Ukraine",
    "apps": [
      {
        "title": "WhatsApp Messenger",
        "link": "https://play.google.com/store/apps/details?id=com.whatsapp",
        "rating": 4.3,
        "thumbnail": "https://play-lh.googleusercontent.com/bYtqbOcTYOlgc6gqZ2rwb8lptHuwlNE75zYJu6Bn076-hTmvd96HH-6v7S0YUAAJXoJN=s512-rw"
      },
      {
        "title": "Telegram",
        "link": "https://play.google.com/store/apps/details?id=org.telegram.messenger",
        "rating": 3.9,
        "thumbnail": "https://play-lh.googleusercontent.com/ZU9cSsyIJZo6Oy7HTHiEPwZg0m2Crep-d5ZrfajqtsH-qgUXSqKpNA2FpPDTn-7qA5Q=s512-rw"
      },
      {
        "title": "Instagram",
        "link": "https://play.google.com/store/apps/details?id=com.instagram.android",
        "rating": 4.0,
        "thumbnail": "https://play-lh.googleusercontent.com/VRMWkE5p3CkWhJs6nv-9ZsLAs1QOg5ob1_3qg-rckwYW7yp1fMrYZqnEFpk0IoVP4LM=s512-rw"
      },
      ... other apps
    ]
  }
]

另外,你可以使用SerpApi的Google Play Apps Store API,它会绕过搜索引擎的阻塞,你不必从头开始创建解析器并维护它。
程式码范例:

from serpapi import GoogleSearch
from urllib.parse import urlsplit, parse_qsl
import os, json

countries = [
    {
        "country_code": "us",
        "country_name": "United States"
    },
    {
        "country_code": "uk",
        "country_name": "United Kingdom"
    },
    {
        "country_code": "ua",
        "country_name": "Ukraine"
    }
]

google_play_apps = []

for country in countries:
    params = {
        # https://docs.python.org/3/library/os.html#os.getenv
        'api_key': os.getenv('API_KEY'),    # your serpapi api
        'engine': 'google_play',            # SerpApi search engine
        'store': 'apps',                    # Google Play Apps
        'hl': 'en',                         # language 
        'gl': country['country_code'],      # country of the search
    }
    search = GoogleSearch(params)           # where data extraction happens on the SerpApi backend

    data = {
        'country': country['country_name'],
        'apps': []
    }

    while True:
        result_dict = search.get_dict()     # JSON -> Python dict

        if result_dict.get('organic_results') is None: break

        for result in result_dict.get('organic_results'):
            for item in result['items']:
                data['apps'].append(item)

        google_play_apps.append(data)

        if 'next' in result_dict.get('serpapi_pagination', {}):
            search.params_dict.update(dict(parse_qsl(urlsplit(result_dict.get('serpapi_pagination').get('next')).query)))
        else:
            break

print(json.dumps(google_play_apps, indent=2, ensure_ascii=False))

输出将是相同的。

相关问题