[Python] 纯文本查看 复制代码
import requests
import openpyxl
MAX_PAGE = 3
IS_SETTING_TITLE = False
# url = 'https://stock.xueqiu.com/v5/stock/screener/fund/list.json?type=18&parent_type=1&order=desc&order_by=percent&page=1&size=30'
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) '
'Chrome/107.0.0.0 Safari/537.36 Edg/107.0.1418.62',
'Cookie': 's=ci12owalds;device_id=bf170c1a5ad2e8f024c7daaa8ea85226; '
'Hm_lvt_1db88642e346389874251b5a1eded6e3=1664207247,1664350847; xq_a_token=df4b782b118f7f9cabab6989b39a24cb04685f95; xqat=df4b782b118f7f9cabab6989b39a24cb04685f95; xq_r_token=3ae1ada2a33de0f698daa53fb4e1b61edf335952; xq_id_token=eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJ1aWQiOi0xLCJpc3MiOiJ1YyIsImV4cCI6MTY3MjE4Njc1MSwiY3RtIjoxNjY5ODkyMDk3MDA1LCJjaWQiOiJkOWQwbjRBWnVwIn0.R7xVHyE3IoYwNn_YuJIIsuApsxdEf0e-cFwXSzaJRaMWLoHVBua77D5y3SBKbd7EUEZx7BbSn_Ip9JgIO2F66vVWxvMEc1hO6IyAIy-Sz3KXHF4FOeJsAevLtXRV2JW2MfQZW2KaPXpNJSFpy7t15ER-1K4jI9wd9kpYPsl8c3du3m4pSp7TKd-fhMwXFYseOIlASUIg-Mp-zdzUDbPIjm6vV9enbnK_30Cg-jnsXFVb3QUnijVYVAVRuX5kLFQbXKpMUnW4KorKVPf0TNZgM7Hx0UshevE0n3tWLsBErV_W3NJ_lc6NYtTQraxSmBUFaVcahBi1xbilHPwjsBkh9w; u=691669892154166',
'Origin': 'https://xueqiu.com',
'Referer': 'https://xueqiu.com/hq', }
wb = openpyxl.Workbook()
wk = wb.active
for page in range(1, MAX_PAGE + 1):
url = f'https://stock.xueqiu.com/v5/stock/screener/fund/list.json?type=18&parent_type=1&order=desc&order_by=percent&page={page}&size=30'
response = requests.get(url=url, headers=headers)
json_data = response.json()
data = json_data['data']['list']
if not IS_SETTING_TITLE:
wk.append(list(data[0].keys()))
IS_SETTING_TITLE = True
for v in data:
wk.append([str(i) if type(i) is not list else ','.join(i) for i in v.values()])
wb.save("stock.xlsx")
|