You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
hnu202209100129 e3fc2a4a7d
Update README.md
2 years ago
README.md Update README.md 2 years ago

README.md

table_container

import requests

from lxml import etree

import csv

import pandas as pd

import matplotlib.pyplot as plt

url = "https://www.bitpush.news/covid19/"

headers = { "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36" }

response = requests.get(url, headers=headers)

html = response.text

html

parse = etree.HTMLParser(encoding='utf-8')

doc = etree.HTML(html)

country = doc.xpath('//div[@class="card-content"]//div//ul/li//div[@class="star-logo"]//div[@class="star-country"]//span[@class="taro-text star-country-text"]/text()')

worddict={}

for word in country:

if word in worddict:

    worddict[word]+=1

else:

    worddict[word]=1

list1=sorted(worddict.items(),key=lambda x:x[1], reverse = True) #排序

list2=[]

list3=[]

for i in range(len(list1)):

list2.append(list1[i][0])

list3.append(list1[i][1])

message = list(zip(list2, list3))

names=("country", "person")

message.insert(0, names)

message

with open("content.csv", "w") as f:

w = csv.writer(f)

w.writerows(message)

df = pd.read_csv("content.csv", encoding='gbk')

df.head()

df.info()

df1 = df.head(10)

df1

plt.rcParams['font.sans-serif'] = ['SimHei']

plt.rcParams['figure.figsize'] = (10, 5) # 设置figure_size尺寸

x = df1["country"].values

y = df1["person"].values

plt.bar(x, y)

plt.xlabel("国家",fontsize=14)

plt.ylabel("确诊人数",fontsize=14)

plt.show()