ibrahimch/google-play-scraper

用于从Google Play获取应用数据的PHP爬虫

安装: 4

依赖: 0

建议者: 0

安全: 0

星标: 1

关注者: 1

分支: 65

语言:HTML

0.3.0 2019-06-16 17:42 UTC

This package is auto-updated.

Last update: 2024-09-29 04:49:51 UTC


README

Build Status

一个从Google Play获取应用数据的PHP爬虫。

安装

在您的 composer.json 文件中将 raulr/google-play-scraper 添加为依赖项

$ composer require raulr/google-play-scraper

用法

首先创建一个 Scraper 实例。

use Raulr\GooglePlayScraper\Scraper;

$scraper = new Scraper();

有几种方法可以配置默认行为

  • setDelay($delay): 设置请求Google Play站点的延迟(以毫秒为单位)。
  • setDefaultLang($lang): 设置所有请求的默认语言。 $lang 必须是一个 ISO_639-1 两位字母语言代码。如果未设置,则默认语言为 en
  • setDefaultCountry($country): 设置所有请求的默认国家。 $country 必须是一个 ISO_3166-1 两位字母国家代码。如果未设置,则默认国家为 us

getApp

给定ID获取应用信息。

参数

  • $id: Google Play应用标识符。
  • $lang: (可选,默认为 null):覆盖默认语言。
  • $country: (可选,默认为 null):覆盖默认国家。

示例

$app = $scraper->getApp('com.mojang.minecraftpe');

返回

array (
  'id' => 'com.mojang.minecraftpe',
  'url' => 'https://play.google.com/store/apps/details?id=com.mojang.minecraftpe',
  'image' => 'https://lh3.googleusercontent.com/VSwHQjcAttxsLE47RuS4PqpC4LT7lCoSjE7Hx5AW_yCxtDvcnsHHvm5CTuL5BPN-uRTP=s180',
  'title' => 'Minecraft',
  'author' => 'Mojang',
  'author_link' => 'https://play.google.com/store/apps/developer?id=Mojang',
  'categories' => array (
    'Arcade',
    'Action & Adventure',
  ),
  'price' => '$6.99',
  'screenshots' => array (
    'https://lh3.googleusercontent.com/28b1vxJQe916wOaSVB4CmcnDujk8M2SNaCwqtQ4cUS0wYKYn9kCYeqxX0uyI2X-nQv0=w720-h310',
    'https://lh3.googleusercontent.com/VkLE0e0EDuRID6jdTE97cC8BomcDReJtZOem9Jlb14jw9O7ytAGvE-2pLqvoSJ7w3IdK=w720-h310',
    // [...]
  ),
  'description' => 'Explore infinite worlds and build everything from the simplest of homes to the grandest of castles[...]',
  'description_html' => 'Explore infinite worlds and build everything from the simplest of homes to the grandest of castles[...]',
  'rating' => 4.5,
  'votes' => 2736136,
  'last_updated' => 'May 23, 2019',
  'size' => null,
  'downloads' => '10,000,000+',
  'version' => '1.11.4.2',
  'supported_os' => '4.2 and up',
  'content_rating' => 'Everyone 10+',
  'whatsnew' => 'What\'s new in version 1.11?[...]',
)

以下字段可能包含一个 null 值:pricelast_updatedsizedownloadsversionsupported_oscontent_ratingwhatsnewvideo_linkvideo_imagepricenull 表示该应用是免费的。

getApps

给定ID获取多个应用的信息。

参数

  • $ids: Google Play应用标识符数组。
  • $lang: (可选,默认为 null):覆盖默认语言。
  • $country: (可选,默认为 null):覆盖默认国家。

示例

$app = $scraper->getApps(array(
    'com.mojang.minecraftpe',
    'com.google.android.youtube',
));

getCategories

返回一个包含Google Play中现有类别的数组。

示例

use Raulr\GooglePlayScraper\Scraper;

$scraper = new Scraper();
$categories = $scraper->getCategories();

返回

array (
  'ART_AND_DESIGN',
  'AUTO_AND_VEHICLES',
  'BEAUTY',
  'BOOKS_AND_REFERENCE',
  'BUSINESS',
  'COMICS',
  'COMMUNICATION',
  'DATING',
  'EDUCATION',
  'ENTERTAINMENT',
  'EVENTS',
  'FINANCE',
  'FOOD_AND_DRINK',
  'HEALTH_AND_FITNESS',
  'HOUSE_AND_HOME',
  'LIBRARIES_AND_DEMO',
  'LIFESTYLE',
  'MAPS_AND_NAVIGATION',
  'MEDICAL',
  'MUSIC_AND_AUDIO',
  'NEWS_AND_MAGAZINES',
  'PARENTING',
  'PERSONALIZATION',
  'PHOTOGRAPHY',
  'PRODUCTIVITY',
  'SHOPPING',
  'SOCIAL',
  'SPORTS',
  'TOOLS',
  'TRAVEL_AND_LOCAL',
  'VIDEO_PLAYERS',
  'ANDROID_WEAR',
  'WEATHER',
  'GAME',
  'GAME_ACTION',
  'GAME_ADVENTURE',
  'GAME_ARCADE',
  'GAME_BOARD',
  'GAME_CARD',
  'GAME_CASINO',
  'GAME_CASUAL',
  'GAME_EDUCATIONAL',
  'GAME_MUSIC',
  'GAME_PUZZLE',
  'GAME_RACING',
  'GAME_ROLE_PLAYING',
  'GAME_SIMULATION',
  'GAME_SPORTS',
  'GAME_STRATEGY',
  'GAME_TRIVIA',
  'GAME_WORD',
  'FAMILY',
  'FAMILY_ACTION',
  'FAMILY_BRAINGAMES',
  'FAMILY_CREATE',
  'FAMILY_EDUCATION',
  'FAMILY_MUSICVIDEO',
  'FAMILY_PRETEND'
)

getCollections

返回一个包含Google Play中现有集合的数组。

示例

$collections = $scraper->getCollections();

返回

array (
  'topselling_free',
  'topselling_paid',
  'topselling_new_free',
  'topselling_new_paid',
  'topgrossing',
  'movers_shakers',
)

getList

根据集合检索Google Play应用列表,并可选项按类别过滤。

参数

  • $collection: 要检索的Google Play集合。有关可能值,请参阅 getCollections
  • $category: (可选,默认为 null) 通过此类别过滤请求。有关可能值,请参阅 getCategories
  • $lang: (可选,默认为 null):覆盖默认语言。
  • $country: (可选,默认为 null):覆盖默认国家。

示例

$apps = $scraper->getList('topselling_free', 'SOCIAL');

返回

array (
  array (
    'id' => 'com.facebook.katana',
    'url' => 'https://play.google.com/store/apps/details?id=com.facebook.katana',
    'title' => 'Facebook',
    'image' => 'https://lh3.googleusercontent.com/ZZPdzvlpK9r_Df9C3M7j1rNRi7hhHRvPhlklJ3lfi5jk86Jd1s0Y5wcQ1QgbVaAP5Q=w340',
    'author' => 'Facebook',
    'rating' => 3.9888803958892822,
    'price' => null,
  ),
  array (
    'id' => 'com.snapchat.android',
    'url' => 'https://play.google.com/store/apps/details?id=com.snapchat.android',
    'title' => 'Snapchat',
    'image' => 'https://lh4.ggpht.com/vdK_CsMSsJoYvJpYgaj91fiJ1T8rnSHHbXL0Em378kQaaf_BGyvUek2aU9z2qbxJCAFV=w340',
    'author' => 'Snapchat Inc',
    'rating' => 3.8660063743591309,
    'price' => null,
  ),
  // [...]
)

getDetailList

getList 相同,但返回完整的详细应用数据。为了获取每个列表中的应用的详细信息,将进行额外的请求。

getListChunk

检索Google Play应用列表的一部分。

参数

  • $collection: 要检索的Google Play集合。有关可能值,请参阅 getCollections
  • $category: (可选,默认为 null) 通过此类别过滤请求。有关可能值,请参阅 getCategories
  • $start: (可选,默认为 0):起始索引。必须在 0180 之间。
  • $num: (可选,默认为 60):要检索的应用数量。必须在 0120 之间。
  • $lang: (可选,默认为 null):覆盖默认语言。
  • $country: (可选,默认为 null):覆盖默认国家。

示例

$apps = $scraper->getListChunk('topselling_free', 'SOCIAL', 20, 80);

getDetailListChunk

getListChunk 相同,但返回完整的详细应用数据。为了获取列表中的每个应用的详细信息,将进行额外的请求。

getSearch

根据搜索查询检索Google Play应用列表,并可选项按价格和评分过滤。

参数

  • $query: 搜索查询。
  • $price: (可选,默认为 all) 通过价格过滤请求。可能的值:allfreepaid
  • $rating: (可选,默认为 all) 通过评分过滤请求。可能的值:all4+
  • $lang: (可选,默认为 null):覆盖默认语言。
  • $country: (可选,默认为 null):覆盖默认国家。

示例

$apps = $scraper->getSearch('unicorns', 'free', '4+');

getDetailSearch

getSearch 相同,但返回完整的应用程序数据。为了获取每个应用程序的详细信息,会为搜索结果中的每个应用程序发出一个额外的请求。