gpt4 book ai didi

python - 创建一个 python 网络抓取工具来获取 Google Play 商店应用程序的元数据

转载 作者:行者123 更新时间:2023-12-01 09:33:27 26 4
gpt4 key购买 nike

我对 Python 非常陌生,并且非常有兴趣了解更多信息。我目前正在做的一门类(class)给了我一个任务...

  • 请编写一个小型 Python 脚本,用于抓取 Google Play 网络商店 ( https://play.google.com/store ) 中的特定应用列表,并将应用商店列表信息存储在输出文件夹中。
  • 脚本应从应用程序页面提取以下信息:icon , title , descriptionscreenshots .
  • 我应该能够通过以下命令运行脚本:python app_fetcher.py <app_id> 。然后,元数据应存储在当前目录的文件夹中(例如 ./<app_id> )
  • 奖励积分!还可以获取应用商店列表副标题或任何您感兴趣的内容。

我已经开始执行此操作,但不确定如何实际执行脚本的网络抓取部分。有谁可以指教一下。我不知道要使用哪些库或要调用哪些函数。我在网上查看过,但这都涉及安装额外的软件包。这是我到目前为止所拥有的,任何帮助将不胜感激!!!...

# Function to crawl Google Play Store and obtain data
def web_crawl(app_id):
import os, sys, urllib2
try:
# Obtain the URL for the app
url = "https://play.google.com/store/apps/details?id=" + app_id

# open url for reading
response = urllib2.urlopen(url)

# Get path of py file to store txt file locally
fpath = os.path.dirname(os.path.realpath(sys.argv[0]))

# Open file to store app metadata
with open(fpath + "\web_crawl.txt", "w") as f:
f.write("Google Play Store Web Crawler \n")
f.write("Metadata for " + app_id + "\n")
f.write("*************************************** \n")
f.write("Icon: " + "\n")
f.write("Title: " + "\n")
f.write("Description: " + "\n")
f.write("Screenshots: " + "\n")

# Added subtitle
f.write("Subtitle: " + "\n")

# Close file after write
f.close()
except urllib2.HTTPError, e:
print("HTTP Error: ")
print(e.code)
except urllib2.URLError, e:
print("URL Error: ")
print(e.args)

# Call web_crawl function
web_crawl("com.cmplay.tiles2")

最佳答案

我建议你使用BeautifulSoup。首先,使用此代码

from bs4 import BeautifulSoup
r = requests.get("url");
# optionally check status code here
soup = BeautifulSoup(r.text)

使用 soup 对象,您可以使用选择器从页面中提取元素

在此处了解更多信息:https://www.crummy.com/software/BeautifulSoup/bs4/doc/

关于python - 创建一个 python 网络抓取工具来获取 Google Play 商店应用程序的元数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49754701/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com