From 53416c82ea73bf6e759a9b24c7822045d314a7ba Mon Sep 17 00:00:00 2001 From: hnu201807010805 Date: Sat, 10 Dec 2022 17:25:14 +0800 Subject: [PATCH] Update README.md --- README.md | 50 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 57fc8e0..9adcb61 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,50 @@ # index_500top - +import requests +url = "https://top.chinaz.com/gongsitop/index_500top.html" +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" +} +response = requests.get(url, headers=headers) +html = response.text +html +import re +company = re.findall('(.+?)', html) +person = re.findall('法定代表人:(.+?)

', html) +signDate = re.findall('注册时间:(.+?)

', html) +category = re.findall('证券类别:(.+?)

', html) +pageOne = list(zip(company, person, signDate, category)) +message = [] +for page in range(16): + if page == 0: + url = "https://top.chinaz.com/gongsitop/index_500top.html" + else: + url = "https://top.chinaz.com/gongsitop/index_500top_{}.html".format(page + 1) + response = requests.get(url, headers=headers) + html = response.text + company = re.findall('(.+?)', html) + person = re.findall('法定代表人:(.*?)

', html) + signDate = re.findall('注册时间:(.*?)

', html) + category = re.findall('证券类别:(.*?)

', html) + pageOne = list(zip(company, person, signDate, category)) + message.extend(pageOne) +import csv +with open("content.csv", "w") as f: + w = csv.writer(f) + w.writerows(message) +!cat content.csv +import pandas as pd +df = pd.read_csv("content.csv", names=["company", "person", "signDate", "category"]) +df.head() +df.info() +df1 = df.groupby("category").count()["company"] +df1 +%matplotlib inline +import matplotlib.pyplot as plt +plt.rcParams['font.sans-serif'] = ['SimHei'] +labels = df1.index +sizes = df1.values +fig1, ax1 = plt.subplots() +ax1.pie(sizes, labels=labels, autopct='%d%%',radius=2,textprops={'fontsize': 20}, + shadow=False, startangle=90) +ax1.axis() +plt.show()