import pandas as pd
import os
import requests
# 创建“独角兽榜单”文件夹
desktop_path = os.path.join(os.path.expanduser("~"), 'Desktop')
foldername = '独角兽榜单'
folderpath = os.path.join(desktop_path, foldername)
if not os.path.exists(folderpath):
os.makedirs(folderpath)
# 获取 Hurun 榜单并保存为 Excel 文件
url = 'https://www.hurun.net/zh-CN/Rank/HsRankDetailsList?num=2VXMC96V&search=&offset=0&limit=1311'
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3',
'Referer': 'https://www.google.com/'
}
response = requests.get(url, headers=headers).json()
df_hurun = pd.json_normalize(response['rows'])
selected_columns = ['hs_Rank_Unicorn_Ranking', 'hs_Rank_Unicorn_Wealth', 'hs_Rank_Unicorn_ChaName_Cn', 'hs_Rank_Unicorn_ComName_Cn', 'hs_Rank_Unicorn_ComHeadquarters_Cn', 'hs_Rank_Unicorn_Industry_Cn']
df_hurun_selected = df_hurun[selected_columns]
filename = 'hurun_unicorns.xlsx'
filepath = os.path.join(folderpath, filename)
df_hurun_selected.to_excel(filepath, index=False)
打开F12-网络,在JS或fetch或文档中找到需要请求的url