Python 在列表中自动执行google play搜索项目

Python 在列表中自动执行google play搜索项目,python,function,web-scraping,automation,web-crawler,Python,Function,Web Scraping,Automation,Web Crawler,我正在从事一个python项目,我需要了解该公司拥有哪些应用程序。 例如,我有一个列表: company_name = ['Airbnb', 'WeFi'] 我想编写一个python函数/程序来执行以下操作: 一,。让它自动搜索Play store列表中的项目 二,。如果公司名称匹配,即使它只匹配名字,例如“Airbnb”将匹配“Airbnb,inc” 然后,它将点击进入页面并读取其类别 如果该公司有多个应用程序,它将对所有应用程序执行相同的操作 公司的每个应用程序信息都存储在tuple=

我正在从事一个python项目,我需要了解该公司拥有哪些应用程序。 例如,我有一个列表:

company_name = ['Airbnb', 'WeFi']
我想编写一个python函数/程序来执行以下操作:

一,。让它自动搜索Play store列表中的项目

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

  • 然后,它将点击进入页面并读取其类别

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

  • 公司的每个应用程序信息都存储在
    tuple={app name,category}

  • 期望的最终结果是元组列表

  • 例如:

    结果:
    airbnb
    元组

    结果:
    [('airbnb','Travel')]

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


    我知道selenium可以自动执行“加载更多”功能,但我不确定我可以使用什么样的软件包

    我写了一个小演示,可以帮助您实现目标。我用的是咖啡和漂亮的汤。这并不完全是你想要的,但它可以很容易地适应

    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')
    
    我的谷歌脚本

    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')
    

    这里有另一个以编程方式搜索google play的选项:


    (这是nodejs,不是python)

    你有代码刮一个页面吗?是的,我知道如何刮谷歌页面。但是我在“自动”部分遇到了麻烦。我不知道如何在列表中自动搜索项目并自动点击页面。请添加farI使用beautifulsoup和urllib.request实现的代码。今晚回家后我会上传密码!谢谢别担心,等你打招呼@Peter234时我会看一看,这太棒了!你提供了一个新的视角来解决我的问题。我会深入调查的!!再次感谢!!我只是想从底层选民那里了解我的答案有什么问题。难道我不应该发布这么多代码吗?@Peter234不要关注单一的否决票。如果有两个,是时候采取行动了,否则就忽略它们。有些人只是比其他人更疯狂:)
    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')
    
    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')
    
    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);