通过点击显示全部ajax接口加载获取数据
import requests
import re
from lxml import etree
import csvdef get_stock_lists(id):url2 = f"https://fundf10.eastmoney.com/FundArchivesDatas.aspx?type=jjcc&code={id}&topline=10&year=2021&month=3&rt=0.7905805810304118"tables2 = requests.get(url2)str1 = tables2.textstr2 = re.findall('content:"(.*?)",',str1)[0]html1 = etree.HTML(str2)return html1.xpath("//tr/td[3]//text()")[:10]ids=["001297","006228","180012"]
stocks =[]
for i in ids:stock = get_stock_lists(i)stocks.append(stock)stocks
获取优秀基金人气组合持仓基金情况
蛋卷基金:https://danjuanfunds.com/activity/GroupBigV
import requests## 获取收益高排序的人气组合
headers={
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36"
}
h1 = requests.get("https://danjuanfunds.com/djapi/fundx/portfolio/v3/plan/united/page?tab=4&page=1&size=20&default_order=1&invest_strategy=&type=&manager_type=&yield_between=&mz_between=",headers=headers)
## 获取每个组合的投资基金情况
all={}
for i in h1.json()["data"]["items"]:name = i["plan_name"]h2 = requests.get("https://danjuanfunds.com/djapi/plan/position/detail?plan_code={}".format(i["plan_code"]),headers=headers).json()stocks = []for j in h2["data"]["items"]:stocks.append(j["fd_name"])all[name] = stocks