当前位置:网站首页>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 




边栏推荐
- JS Array isaarray () Type of
- Symbol类型
- The new idea 2022.2 was officially released, and the new features are nice
- Minimum exchange times
- Ugui source code analysis - maskablegraphic
- uva11389
- kettle
- FTP service and configuration
- OSPF comprehensive experimental configuration
- Customize the default width and height of kindeditor rich text
猜你喜欢

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

Ways to improve the utilization of openeuler resources 01: Introduction

Industrial controller, do you really know your five insurances and one fund?

Hcip day 10 (initial BGP border gateway protocol)

Ugui source code analysis - stencilmaterial

什么是IMU?

TCP data transmission and performance

How will you answer the "Hello world" challenge written in C language?

微信公众号在线客服接入发方法和功能详解

JS array isaarray() typeof
随机推荐
What is the security of Treasury reverse repo
Error code 0x80004005
Some properties of differential array operation
MariaDB related instructions
Is the reverse repurchase of treasury bonds safe? How to open an account online?
Redux Usage Summary
Bingbing learning notes: basic operation of vim tool
An introductory example of structure and combinatorial ideas in go language
Summernote font displays Chinese
OSPF comprehensive experimental configuration
Symbol type
CMT registration - Google Scholar ID, semantic scholar ID, and DBLP ID
Svn: e00002: can't convert string from 'UTF-8' to native encoding problem solving
How will you answer the "Hello world" challenge written in C language?
C. Minimum Ties-Educational Codeforces Round 104 (Rated for Div. 2)
Insist on accompanying study
How does the small program mall refine the operation of members?
String.split()最详细源码解读及注意事项
How to write selenium's testng.xml
Take you into the world of MySQL mvcc