当前位置:网站首页>08 reptile project
08 reptile project
2022-07-24 03:16:00 【Yinma Hanhai】

1. Collect the latest epidemic data of countries all over the world 
You have to put json Turn into python, use python The code gets the desired data , It's transforming into json Deposit in json In the document

import requests
from bs4 import BeautifulSoup
import re
import json
# 1. Send a request , Get the epidemic Homepage
response = requests.get('https://ncov.dxy.cn/ncovh5/view/pneumonia')
home_page = response.content.decode() # Get the homepage content of the response
# 2. From the front page of the epidemic , Extract the latest epidemic data of various countries
soup = BeautifulSoup(home_page, 'lxml') # structure BeautifulSoup object
script = soup.find(id='getListByCountryTypeService2true')
# print(script) # Describe its contents
# ( Next I need this json Formatted data , You need to use regular extraction )
# 3. From the epidemic data , obtain json Format string
json_str = re.findall(r'\[.+\]', script.string)[0]
# print(json_str) # The standard json Format string
# 4. hold json Format string to python type
last_day_corona_virus = json.loads(json_str)
print(last_day_corona_virus) # So get a python Data of type ( External interview list , There's a dictionary in it , Each dictionary represents the epidemic information of a country )
# 5. With json Format preservation , Epidemic data of various countries on the latest day
with open('data/last_day_corona_virus.json', 'w', encoding='UTF-8') as fp:
json.dump(last_day_corona_virus, fp, ensure_ascii=False)
''' Be careful : If there is an error here ‘gbk’ The decoder cannot be compiled , Can be in open() Specify the inside encoding='UTF-8' that will do '''

2. Acquisition from 01 month 23 Epidemic data of countries all over the world since Japan 




边栏推荐
- Lumberyard game engine of o3de
- Simulink code generation: variable subsystem and its code
- Hcip day 9 notes (OSPF routing feedback, routing policy, and Configuration Guide)
- Industrial controller, do you really know your five insurances and one fund?
- JS Array isaarray () Type of
- An introductory example of structure and combinatorial ideas in go language
- Go IO operation - file read
- Xiaodi and Xiaohui
- Insist on accompanying study
- Symbol type
猜你喜欢

Take you into the world of MySQL mvcc

The process of solving a bug at work

198. House raiding

openEuler 资源利用率提升之道 01:概论

Ways to improve the utilization of openeuler resources 01: Introduction

Customize the default width and height of kindeditor rich text

Expressions régulières \ \ B \ \ b compréhension de l'appariement des limites des mots

Nodejs builds cloud native microservice applications based on dapr, a quick start guide from 0 to 1

C动态内存管理详解

什么是IMU?
随机推荐
The implementation in unity determines whether missing or null
Test interview questions
Symbol type
Unity Message push
[MySQL learning] install and use multiple versions of MySQL, MySQL 8 and MySQL 5.7 at the same time, compressed version
SolidWorks CAM data cannot be recovered because a processed part has been detected.
Water topic: connect rainwater
正则表达式 \b \B 深入浅出理解单词边界的匹配
[hdlbits questions] Verilog language (2) vectors
Summernote font displays Chinese
数据湖:开源数据湖方案DeltaLake、Hudi、Iceberg对比分析
Lcd1602——斌哥51
LCD1602 - binge 51
SolidWorks cannot reference references
OSPF comprehensive experimental configuration
Ugui source code analysis - iclippable
移动通信的新定义:R&SCMX500 将提高5G设备的IP数据吞吐量
JIRA automation experience sharing for 2 years
New definition of mobile communication: R & scmx500 will improve the IP data throughput of 5g devices
Generate 13 bit barcode