所以我正在尝试通过一个网站了解哥伦比亚目前确诊了多少冠状病毒病例。我只需要显示案例数量,并且我正在使用 bs4。然而,我知道有关编程的基本知识,但我不懂Python。这就是我所拥有的
import bs4
import requests
response = requests.get("https://es.wikipedia.org/wiki/Pandemia_de_enfermedad_por_coronavirus_de_2020_en_Colombia")
if response is not None:
html = bs4.BeautifulSoup(response.text, 'html.parser')
title = html.select(".infobox")[0].text
paragraphs = html.select("tr")
#for para in paragraphs:
#print (para.text)
mylist = soup.find_all('td')
print(mylist.text)
最佳答案
I'm trying to get how many cases of coronavirus are currently confirmed in Colombia
有很多api's拥有可用的实时数据,您无需从维基百科中获取此信息。这是一个 python
示例:
import requests
j = requests.get("https://pomber.github.io/covid19/timeseries.json").json()
# j['Colombia'] # full `timeseries` that you can import in pandas
# to get latest available date, use [-1]:
confirmed = j['Colombia'][-1]['confirmed']
deaths = j['Colombia'][-1]['deaths']
recovered = j['Colombia'][-1]['recovered']
# {'date': '2020-4-24', 'confirmed': 4881, 'deaths': 225, 'recovered': 1003}
顺便说一句,我将此病毒称为con视频19
关于python-3.x - 我如何使用 beautifulsoup 从维基百科表中提取一条数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61429456/