import json import time,datetime import os import requests import re session = requests.Session() session.headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36'} s1=session.get('http://data.eastmoney.com/kzz/') a1=re.search("token=.*?&cmd",s1.text,flags=0) token=a1.group(0).replace("token=","").replace("&cmd","") time.sleep(0.1) h1="http://dcfm.eastmoney.com/em_mutisvcexpandinterface/api/js/get?type=KZZ_LB2.0&token={0}&cmd=&st=STARTDATE&sr=-1&p=1&ps={1}&rt=52898794".format(token,"200") s2=session.get(h1) a2=re.search("[.*?]",s2.text,flags=0) ar1=json.loads(a2.group(0)) ar2=[] for q in ar1: arr1={"BONDCODE":q["BONDCODE"],"SNAME":q["SNAME"],"STARTDATE":q["STARTDATE"],"CORRESCODE":q["CORRESCODE"],"CORRESNAME":q["CORRESNAME"],"SWAPSCODE":q["SWAPSCODE"],"SECURITYSHORTNAME":q["SECURITYSHORTNAME"],"GDYX_STARTDATE":q["GDYX_STARTDATE"]} ar2.append(arr1) print(len(ar2))