From 1a2fcfebe04aa7893bbed8a09f618f3a18623e13 Mon Sep 17 00:00:00 2001 From: hnu202309010319 <3270957324@qq.com> Date: Sun, 9 Jun 2024 00:27:54 +0800 Subject: [PATCH] ADD file via upload --- 中国500强公司信息爬取.py | 35 +++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 中国500强公司信息爬取.py diff --git a/中国500强公司信息爬取.py b/中国500强公司信息爬取.py new file mode 100644 index 0000000..c71b4b3 --- /dev/null +++ b/中国500强公司信息爬取.py @@ -0,0 +1,35 @@ +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('(.+?)', html) + m=re.findall('(.*?)亿注册资本', 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() \ No newline at end of file