访问https://m.111.com.cn/yyw/activities/broadcast/#/home 用python获取以下数据内容:国内各地区疫情:新增、累计、治愈、死亡; 国外各国疫情:新增、累计、治愈、死亡
时间: 2023-07-10 21:20:32 浏览: 81
好的,我可以帮你解决这个问题。我们需要用到 Python 的 requests 和 BeautifulSoup 库来实现网页内容的获取和解析。
以下是代码实现:
```python
import requests
from bs4 import BeautifulSoup
url = 'https://m.111.com.cn/yyw/activities/broadcast/#/home'
# 发送 GET 请求,获取网页内容
response = requests.get(url)
# 解析网页内容
soup = BeautifulSoup(response.content, 'html.parser')
# 查找国内各地区疫情信息
china_data = soup.find('div', {'class': 'area-area'}).find_all('div', {'class': 'text-center'})
# 获取新增、累计、治愈、死亡数据
china_new = china_data[0].text.strip()
china_total = china_data[1].text.strip()
china_cure = china_data[2].text.strip()
china_death = china_data[3].text.strip()
# 查找国外各国疫情信息
world_data = soup.find('div', {'class': 'area-world'}).find_all('div', {'class': 'text-center'})
# 获取新增、累计、治愈、死亡数据
world_new = world_data[0].text.strip()
world_total = world_data[1].text.strip()
world_cure = world_data[2].text.strip()
world_death = world_data[3].text.strip()
# 打印结果
print('国内疫情数据:')
print('新增:', china_new)
print('累计:', china_total)
print('治愈:', china_cure)
print('死亡:', china_death)
print('国外疫情数据:')
print('新增:', world_new)
print('累计:', world_total)
print('治愈:', world_cure)
print('死亡:', world_death)
```
运行以上代码,就可以获取到国内和国外疫情的相关数据。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)