简体   繁体   English

BeautifulSoup - 无法获取 tbody

[英]BeautifulSoup - Can't get tbody

I'm trying to get a table that is located inside multiple nests.我正在尝试获取位于多个嵌套内的表。 I'm new to Beautifulsoup and I have practiced some simple eeemples.我是 Beautifulsoup 的新手,我练习了一些简单的 eeemples。 The issue is that, I can't understand why my code can't get the "div" tag that has the class "Explorer is-embed".问题是,我不明白为什么我的代码无法获得具有 class “Explorer is-embed”的“div”标签。 Because from that point, I can go deeper to get to the tbody where all the data that I want to scrape are located.因为从那时起,我可以更深入地访问go以到达我要抓取的所有数据所在的 tbody。 thanks for your help in advance.提前感谢您的帮助。

Below is my code:下面是我的代码:

url = "https://ourworldindata.org/covid-cases"
url_content = requests.get(url)
soup = BeautifulSoup(url_content.text, "lxml")
########################
div1 = soup3.body.find_all("div", attrs={"class":"content-wrapper"})
div2 = div1[0].find_all("div", attrs={"class":"offset-content"})
sections = div2[0].find_all('section')
figure = sections[1].find_all("figure")
div3 = figure[0].find_all("div")
div4 = div3[0].find_all("div")

Here is a snapshot of the "div" tag that I'm not getting.这是我没有得到的“div”标签的快照。 Figure数字

Data is dynamically loaded.数据是动态加载的。 Instead, grab the public source csv (other formats available)相反,获取公共源 csv(其他可用格式)

https://ourworldindata.org/coronavirus-source-data https://ourworldindata.org/coronavirus-source-data

import pandas as pd

df = pd.read_csv('https://covid.ourworldindata.org/data/owid-covid-data.csv')
df.head()

Values you see in the Daily new confirmed COVID-19 cases (per 1M) table are calculated from the same data as in that file for the two dates being compared eg您在每日新确认的 COVID-19 病例(每 1M)表中看到的值是根据与该文件中比较的两个日期相同的数据计算得出的,例如

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM