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.
35 lines
1.3 KiB
35 lines
1.3 KiB
6 months ago
|
import requests
|
||
|
import re
|
||
|
import csv
|
||
|
import pandas as pd
|
||
|
import matplotlib.pyplot as plt
|
||
|
headers = {
|
||
|
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36"
|
||
|
}
|
||
|
message = []
|
||
|
for page in range(16):
|
||
|
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)
|
||
|
response = requests.get(url, headers=headers)
|
||
|
html = response.text
|
||
|
company = re.findall('<a.*?target="_blank">(.+?)</a></h3>', html)
|
||
|
m=re.findall('<em>(.*?)亿</em>注册资本', html)
|
||
|
pageOne = list(zip(company,m))
|
||
|
message.extend(pageOne)
|
||
|
with open("content.csv", "w") as f:
|
||
|
w = csv.writer(f)
|
||
|
w.writerows(message)
|
||
|
df = pd.read_csv("content.csv", names=["company","m"],encoding="gbk")
|
||
|
df.head()
|
||
|
plt.rcParams['font.sans-serif'] = ['SimHei']
|
||
|
plt.figure(figsize=(20,10))
|
||
|
plt.bar(df["company"][:20],df["m"][:20])
|
||
|
plt.xticks(range(len(df["company"][:20])),df["company"][:20],rotation=90)
|
||
|
for x,y in zip(range(len(df["m"][:20])),df["m"][:20]):
|
||
|
plt.text(x,y,y,ha="center",va='bottom')
|
||
|
plt.title("注册资金最多公司 top20")
|
||
|
plt.xlabel("公司")
|
||
|
plt.ylabel("资金(亿元)")
|
||
|
plt.show()
|