import requests import json import pandas as pd import time def getTextFromUrl(url): headers = { "Referer": "https://www.chinamoney.com.cn/chinese/bkfrr/", "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 Edg/125.0.0.0" } response = requests.post(url=url,headers=headers) response .encoding = "utf-8" return response def parseResText2jsonlist(text): #在字符串中找到需去掉的内容:"reccords" startIndex = text.find("records") print("获取起始索引,",startIndex) #找到最后一个”】“的位置 endIndex =text.find("]")+1 print("截取索引结束,",endIndex) #通过起始位置和结束位置找到[]之间的数据 str =text[startIndex:endIndex].replace("records","") #将获取的数据解析成json列表 jsonlist = json.loads(str[2:]) return jsonlist if __name__=="__main__":
09-08
2万+