【问题标题】:Automate google play search items in a list自动化列表中的 google play 搜索项目
【发布时间】:2016-08-23 21:51:23
【问题描述】:

我正在做一个 python 项目,我需要找出公司拥有哪些应用程序。 例如,我有一个列表:

company_name = ['Airbnb', 'WeFi']

我想编写一个 python 函数/程序来执行以下操作:

1 .让它自动在 Play 商店的列表中搜索项目

2 。如果公司名称匹配,即使它只匹配名字,例如“Airbnb”将匹配“Airbnb,inc”

  1. 然后它会点击进入页面并读取其类别

  2. 如果公司有多个应用程序,它将对所有应用程序执行相同的操作。

  3. 公司各app信息存储在tuple = {app name, category}

  4. 所需的最终结果将是一个元组列表

例如:

print(company_name[0])
print(type(company_name[0]))

结果:
爱彼迎
元组

print(company_name[0][0])

结果:
[('airbnb','旅行')]

这是许多知识的混合体,我是 python 的新手。所以请给我一些指导,告诉我应该如何开始编写代码。

我了解到 selenium 可以自动执行“加载更多”功能,但我不确定我可以使用什么包?

【问题讨论】:

  • 你有代码可以抓取一页吗?
  • 是的,我知道如何抓取 Google 页面。但是我在执行“自动化”部分时遇到了麻烦。我不知道如何在列表中自动搜索项目并自动点击进入页面。
  • 添加你的代码,让你走得更远
  • 我使用 beautifulsoup 和 urllib.request 来做这件事。我今晚回家后上传代码!谢谢!
  • 别着急,我去看看

标签: python function web-scraping automation web-crawler


【解决方案1】:

我编写了一个小演示,可以帮助您实现目标。我使用了请求和美丽的汤。这不是您想要的,但可以轻松调整。

import requests
import bs4

company_name = "airbnb"
def get_company(company_name):
    r = requests.get("https://play.google.com/store/search?q="+company_name)
    soup = bs4.BeautifulSoup(r.text, "html.parser")
    subtitles = soup.findAll("a", {'class':"subtitle"})
    dev_urls = []
    for title in subtitles:
        try:
            text = title.attrs["title"].lower()
        #Sometimes there is a subtitle without any text on GPlay
        #Catchs the error
        except KeyError:
            continue
        if company_name in text:
            url = "https://play.google.com" + title.attrs["href"]
            dev_urls.append(url)
    return dev_urls

def get_company_apps_url(dev_url):
    r = requests.get(dev_url)
    soup = bs4.BeautifulSoup(r.text, "html.parser")
    titles = soup.findAll("a", {"class":"title"})
    return ["https://play.google.com"+title.attrs["href"] for title in titles]

def get_app_category(app_url):
    r = requests.get(app_url)
    soup = bs4.BeautifulSoup(r.text, "html.parser")
    developer_name = soup.find("span", {"itemprop":"name"}).text
    app_name = soup.find("div", {"class":"id-app-title"}).text
    category = soup.find("span", {"itemprop":"genre"}).text
    return (developer_name, app_name, category)

dev_urls = get_company("airbnb")
apps_urls = get_company_apps_url(dev_urls[0])
get_app_category(apps_urls[0])

>>> get_company("airbnb")
['https://play.google.com/store/apps/developer?id=Airbnb,+Inc']
>>> get_company_apps_url("https://play.google.com/store/apps/developer?id=Airbnb,+Inc")
['https://play.google.com/store/apps/details?id=com.airbnb.android']
>>> get_app_category("https://play.google.com/store/apps/details?id=com.airbnb.android")
('Airbnb, Inc', 'Airbnb', 'Travel & Local')

我的 google 脚本

dev_urls = get_company("google")
apps_urls = get_company_apps_url(dev_urls[0])
for app in apps_urls:
    print(get_app_category(app))

('Google Inc.', 'Google Duo', 'Communication')
('Google Inc.', 'Google Translate', 'Tools')
('Google Inc.', 'Google Photos', 'Photography')
('Google Inc.', 'Google Earth', 'Travel & Local')
('Google Inc.', 'Google Play Games', 'Entertainment')
('Google Inc.', 'Google Calendar', 'Productivity')
('Google Inc.', 'YouTube', 'Media & Video')
('Google Inc.', 'Chrome Browser - Google', 'Communication')
('Google Inc.', 'Google Cast', 'Tools')
('Google Inc.', 'Google Sheets', 'Productivity')

【讨论】:

  • 嗨@Peter234,这太棒了!你提供了一个新的视角来解决我的问题。我会深入研究的!!再次感谢!!
  • 我现在只想从反对者那里了解我的回答有什么问题。我不应该发布这么多代码吗?
  • @Peter234 不要关注单一的反对票。如果有几个,是时候采取行动了,否则就忽略。有些人只是比其他人更疯狂:)
【解决方案2】:

这是另一种以编程方式搜索 google play 的选项:
https://github.com/facundoolano/google-play-scraper/#list

var gplay = require('google-play-scraper');

gplay.list({
    category: gplay.category.GAME_ACTION,
    collection: gplay.collection.TOP_FREE,
    num: 2
  })
  .then(console.log, console.log);

(虽然是 nodejs,但不是 python)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-09
    • 1970-01-01
    • 2014-04-21
    • 2015-08-31
    • 1970-01-01
    • 2023-02-01
    相关资源
    最近更新 更多