From https://www.cnblogs.com/lsz3034/p/12712395.html

点击(此处)折叠或打开

  1. import json
  2. import time,datetime
  3. import os
  4. import requests
  5. import re
  6.  
  7. session = requests.Session()
  8. 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'}
  9. s1=session.get('http://data.eastmoney.com/kzz/')
  10. a1=re.search("token=.*?&cmd",s1.text,flags=0)
  11. token=a1.group(0).replace("token=","").replace("&cmd","")
  12. time.sleep(0.1)
  13. 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")
  14. s2=session.get(h1)
  15. a2=re.search("\[.*?\]",s2.text,flags=0)
  16. ar1=json.loads(a2.group(0))
  17. ar2=[]
  18. for q in ar1:
  19.     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"]}
  20.     ar2.append(arr1)
  21.  
  22.  
  23. print(len(ar2))


08-29 15:07