【发布时间】:2022-01-26 23:25:41
【问题描述】:
我想抓取 google play 应用程序,如果应用程序可用/不可用,我想添加一个值为 True/False 的新列“Google”
这是我的 csv 文件“apkmonk.csv”
Id,Genre,LastUpdated,Name,Package
0, Adventure,"Dec 16, 2021",Merge Mermaids-design home&create magic fish life. apk,com.xjoy.mermaid
1, Adventure,"Dec 10, 2021",Nob's World - Super Run Game apk,org.game69studio.nobworld
2, Adventure,"Dec 15, 2021",Fps Shooting Strike: Gun Games apk,com.mizo.fps.shooting.strike
3, Adventure,"Dec 12, 2021",Ostrich Air Jet Robot Car Game apk,com.cgs.us.police.flying.transform.robot.bike.game
我的代码
from bs4 import BeautifulSoup
import requests
import pandas as pd
df = pd.read_csv('apkmonk.csv')
def googleplay(package):
url=f"https://play.google.com/store/apps/details?id={package}"
html_content = requests.get(url).text
soup = BeautifulSoup(html_content, "lxml")
title= soup.title.text
if "Not Found" in title:
print("not found")
return False
else:
print(" found")
return True
for package in df["Package"]:
if googleplay(package) is True:
df["Google"] = "True"
else:
df["Google"] = "False"
df.to_csv("new.csv", sep=',')
【问题讨论】:
-
您的问题是什么? a.k.a. 在当前代码中什么不起作用?
标签: pandas csv beautifulsoup