Java 在Android中,如何通过软件包名称从play store获取应用程序类别?

Java 在Android中,如何通过软件包名称从play store获取应用程序类别?,java,android,Java,Android,我想通过其唯一标识符(即包名)从play store获取应用程序类别,我使用以下代码,但不返回任何数据。我还尝试使用这个AppsRequest.newBuilder().setAppId(查询)仍然没有帮助。 谢谢 String AndroidId=“dead000beef”; MarketSession会话=新的MarketSession(); 登录(“电子邮件”、“密码”); session.getContext().setandroid(android); String query=“pa

我想通过其唯一标识符(即包名)从play store获取应用程序类别,我使用以下代码,但不返回任何数据。我还尝试使用这个
AppsRequest.newBuilder().setAppId(查询)
仍然没有帮助。 谢谢

String AndroidId=“dead000beef”;
MarketSession会话=新的MarketSession();
登录(“电子邮件”、“密码”);
session.getContext().setandroid(android);
String query=“package:com.king.candycrushsaga”;
AppsRequest AppsRequest=AppsRequest.newBuilder().setQuery(查询).setStartIndex(0)
.setEntriesCount(10).setWithExtendedInfo(true).build();
append(appsRequest,new Callback()){
@凌驾
public void onResult(ResponseContext,AppsResponse-response){
字符串response1=response.toString();
Log.e(“响应”,响应1);
}
});
session.flush();

使用它将提供应用程序的所有信息

这是我所做的,最好且简单的解决方案

https://androidquery.appspot.com/api/market?app=your.unique.package.name  
或者,您可以获取源html并从中获取字符串

https://play.google.com/store/apps/details?id=your.unique.package.name  
从中取出这个字符串-使用split或substring方法

<span itemprop="genre">Sports</span>  
运动
在这种情况下,运动是您的类别

请使用以下脚本:

######## Fetch App names and genre of apps from playstore url, using pakage names ############# 
"""
Reuirements for running this script:
1. requests library
Note: Run this command to avoid insecureplatform warning pip install --upgrade ndg-httpsclient
2. bs4

pip install requests
pip install bs4
"""

import requests
import csv
from bs4 import BeautifulSoup

# url to be used for package
APP_LINK = "https://play.google.com/store/apps/details?id="
output_list = []; input_list = []

# get input file path
print "Need input CSV file (absolute) path \nEnsure csv is of format: <package_name>, <id>\n\nEnter Path:"
input_file_path = str(raw_input())

# store package names and ids in list of tuples
with open(input_file_path, 'rb') as csvfile:
    for line in csvfile.readlines():
        (p, i) = line.strip().split(',')
        input_list.append((p, i))


print "\n\nSit back and relax, this might take a while!\n\n"

for package in input_list:

    # generate url, get html
    url = APP_LINK + package[0]
    r = requests.get(url)

    if not (r.status_code==404):
        data = r.text
        soup = BeautifulSoup(data, 'html.parser')

        # parse result
        x = ""; y = "";
        try:
            x = soup.find('div', {'class': 'id-app-title'})
            x = x.text
        except:
            print "Package name not found for: %s" %package[0]

        try:
            y = soup.find('span', {'itemprop': 'genre'})
            y = y.text
        except:
            print "ID not found for: %s" %package[0]

        output_list.append([x,y])

    else:
        print "App not found: %s" %package[0]

# write to csv file
with open('results.csv', 'w') as fp:
    a = csv.writer(fp, delimiter=",")
    a.writerows(output_list)
使用包装名称从playstore url获取应用程序名称和应用程序类型
"""
运行此脚本的要求:
1.申请图书馆
注意:运行此命令以避免不安全的平台警告pip安装--升级ndg httpsclient
2.bs4
pip安装请求
pip安装bs4
"""
导入请求
导入csv
从bs4导入BeautifulSoup
#要用于包的url
应用程序链接=”https://play.google.com/store/apps/details?id="
输出列表=[];输入列表=[]
#获取输入文件路径
打印“需要输入CSV文件(绝对)路径\n确保CSV的格式为:,\n\n输入路径:
输入文件路径=str(原始输入()
#在元组列表中存储包名称和ID
打开(输入文件路径“rb”)作为csvfile:
对于csvfile.readlines()中的行:
(p,i)=line.strip().split(',')
input_list.append((p,i))
打印“\n\n返回并放松,这可能需要一段时间!\n\n”
对于输入列表中的包:
#生成url,获取html
url=应用程序链接+程序包[0]
r=请求。获取(url)
如果不是(r.status_code==404):
数据=r.text
soup=BeautifulSoup(数据'html.parser')
#解析结果
x=“”;y=“”;
尝试:
x=soup.find('div',{'class':'id-app-title'})
x=x.text
除:
打印“找不到%s”%Package[0]的包名称”
尝试:
y=soup.find('span',{'itemprop':'genre'})
y=y.text
除:
打印“找不到%s”%package[0]的ID”
输出列表。追加([x,y])
其他:
打印“找不到应用程序:%s”%package[0]
#写入csv文件
打开('results.csv','w')作为fp:
a=csv.writer(fp,delimiter=“,”)
a、 writerows(输出列表)

Iam已经在使用它了,但它实际上并没有给出特定软件包名称的信息,或者我可能使用了一些错误的方法,你能帮我提供一个清晰的运行示例吗?@Salman但这并没有给我体育、时尚、生活方式等应用类别?嘿,它工作得很好,但如果google play使用其他语言怎么办?如何只获得英文版的分类?试试这个解决方案:嘿,它工作得很好,但如果谷歌游戏是用其他语言呢?如何仅获取类别的英文版本?
######## Fetch App names and genre of apps from playstore url, using pakage names ############# 
"""
Reuirements for running this script:
1. requests library
Note: Run this command to avoid insecureplatform warning pip install --upgrade ndg-httpsclient
2. bs4

pip install requests
pip install bs4
"""

import requests
import csv
from bs4 import BeautifulSoup

# url to be used for package
APP_LINK = "https://play.google.com/store/apps/details?id="
output_list = []; input_list = []

# get input file path
print "Need input CSV file (absolute) path \nEnsure csv is of format: <package_name>, <id>\n\nEnter Path:"
input_file_path = str(raw_input())

# store package names and ids in list of tuples
with open(input_file_path, 'rb') as csvfile:
    for line in csvfile.readlines():
        (p, i) = line.strip().split(',')
        input_list.append((p, i))


print "\n\nSit back and relax, this might take a while!\n\n"

for package in input_list:

    # generate url, get html
    url = APP_LINK + package[0]
    r = requests.get(url)

    if not (r.status_code==404):
        data = r.text
        soup = BeautifulSoup(data, 'html.parser')

        # parse result
        x = ""; y = "";
        try:
            x = soup.find('div', {'class': 'id-app-title'})
            x = x.text
        except:
            print "Package name not found for: %s" %package[0]

        try:
            y = soup.find('span', {'itemprop': 'genre'})
            y = y.text
        except:
            print "ID not found for: %s" %package[0]

        output_list.append([x,y])

    else:
        print "App not found: %s" %package[0]

# write to csv file
with open('results.csv', 'w') as fp:
    a = csv.writer(fp, delimiter=",")
    a.writerows(output_list)