parent
6e13aedb81
commit
42cb4a61f6
@ -0,0 +1,65 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Created on Thu May 26 17:10:59 2022
|
||||
|
||||
@author: Rare
|
||||
"""
|
||||
|
||||
|
||||
import requests
|
||||
import re
|
||||
|
||||
# 设置请求头信息
|
||||
headers = {
|
||||
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36"
|
||||
}
|
||||
# 使用reqeusts模快发起 GET 请求
|
||||
|
||||
message = []
|
||||
# 总共17个页面的数据
|
||||
for page in range(17):
|
||||
# 组装url
|
||||
if page == 0:
|
||||
url = "https://top.chinaz.com/gongsi/index_zhuce.html"
|
||||
else:
|
||||
url = "https://top.chinaz.com/gongsi/index_zhuce_{}.html".format(page + 1)
|
||||
# 使用reqeusts模快发起 GET 请求
|
||||
response = requests.get(url, headers=headers)
|
||||
html = response.text
|
||||
# 使用 findall 函数来获取数据
|
||||
# 公司名
|
||||
company = re.findall('<a.*?target="_blank">(.+?)</a></h3>', html)
|
||||
# 法定代表人
|
||||
money=re.findall('<em>(.+?)亿</em>注册资本', html)
|
||||
pageOne = list(zip(company, money))
|
||||
# 合并列表
|
||||
message.extend(pageOne)
|
||||
|
||||
A={}
|
||||
for i in range(20):
|
||||
A[message[i][0]]=message[i][1]
|
||||
print(A)
|
||||
import matplotlib.pyplot as plt
|
||||
plt.rcParams['font.sans-serif'] = ['SimHei']
|
||||
plt.rcParams['axes.unicode_minus'] = False
|
||||
M=A.keys()
|
||||
n=A.values()
|
||||
x = range(20)
|
||||
|
||||
N=[]
|
||||
for j in n:
|
||||
N.append(j)
|
||||
N = [float(x) for x in N]
|
||||
print(N)
|
||||
plt.figure(figsize=(45,15))
|
||||
plt.bar(x, N,width=0.6)
|
||||
plt.xticks(x,M)
|
||||
plt.yticks(N,N)
|
||||
for i,j,l in zip(x,N,n):
|
||||
plt.text(i,j,l,size=20,ha='center')
|
||||
plt.xlabel("公司",fontsize=20)
|
||||
plt.ylabel("注册资本/亿元",fontsize=20)
|
||||
plt.title('注册资本前20名的公司')
|
||||
plt.tick_params(labelsize=10)
|
||||
plt.show()
|
||||
print(n)
|
Loading…
Reference in new issue