parent
c1f3054ca2
commit
d3e927d695
@ -0,0 +1,39 @@
|
|||||||
|
import csv
|
||||||
|
import requests
|
||||||
|
import re
|
||||||
|
import pandas as pd
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
page_num = 17
|
||||||
|
message = []
|
||||||
|
for i in range(1, page_num + 1):
|
||||||
|
if i == 1:
|
||||||
|
url = 'https://top.chinaz.com/gongsi/index_zhuce.html'
|
||||||
|
else:
|
||||||
|
url = f'https://top.chinaz.com/gongsi/index_zhuce_{i}.html'
|
||||||
|
headers = {
|
||||||
|
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36 Edg/108.0.1462.46"
|
||||||
|
}
|
||||||
|
resp = requests.get(url,headers=headers)
|
||||||
|
html = resp.text
|
||||||
|
company = re.findall('<a.*?target="_blank">(.+?)</a></h3>', html)
|
||||||
|
register_money = re.findall('<div class="CoDate"><em>(.+?)亿</em>注册资本</div>', html)
|
||||||
|
pageOne = list(zip(company, register_money))
|
||||||
|
message.extend(pageOne)
|
||||||
|
print(f"第{i}页爬取完毕")
|
||||||
|
with open("content.csv", "w", encoding='utf-8', newline='') as f:
|
||||||
|
w = csv.writer(f)
|
||||||
|
w.writerows(message)
|
||||||
|
plt.rcParams['font.sans-serif'] = ['SimHei']
|
||||||
|
df = pd.read_csv("content.csv", names=["company","register_money"])
|
||||||
|
df.sort_values(by=['register_money'])
|
||||||
|
xlabels = df["company"].values[:20]
|
||||||
|
ylabels = df["register_money"].values[:20]
|
||||||
|
data = pd.Series(ylabels, index=xlabels)
|
||||||
|
data.plot(kind='bar')
|
||||||
|
plt.title('注册资金最多的公司 top20')
|
||||||
|
plt.xlabel('公司')
|
||||||
|
plt.xticks(rotation=270,fontsize=5)
|
||||||
|
plt.ylabel('注册资金')
|
||||||
|
for x, y in enumerate(data):
|
||||||
|
plt.text(x, y, y)
|
||||||
|
plt.show()
|
Loading…
Reference in new issue