import requestsimport jsonimport re url = "http://nuyd.eastmoney.com/EM_UBG_PositionChangesInterface/api/js?"headers = {"User-Agent":"Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36"} changeData = []for i in range(1,120): data = { "dtformat":"HH:mm:ss", #"js":"({data:[(x)],pc:(pc)})", "js":"[(x)]", "rows":"64", #"cb":"jQuery17209499783482434403_1568127879385", "page":i, "type": "", "_":"1568127879483" } response = requests.get(url=url,params=data,headers=headers).text if len(response)==2: break else: data_list = json.loads(response) for data in data_list: with open(r‘C:\Users\hui2\Desktop\changeData.txt‘, ‘a+‘, encoding=‘utf-8‘) as f: f.writelines(data+‘\n‘) print("数据已爬取完成")
原文地址:https://www.cnblogs.com/Iceredtea/p/11515933.html
时间: 2024-10-04 02:22:01