|
- # -*- coding: utf-8 -*-
- # version: Python 3.7.0
- import requests,csv
- headers = {'User-Agent': '(KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36'}
- url = 'http://dcfm.eastmoney.com/em_mutisvcexpandinterface/api/js/get'
- def get_json(params, csv_file):
- r = requests.get(url=url, params=params, headers=headers)
- for i in r.json():
- writer = csv.writer(csv_file)
- writer.writerow([v for v in i.values()])#逐行写入csv文件!
- if __name__ == '__main__':
- start_rq = '2019-02-28'#开始日期
- end_rq = '2019-04-13'#结束日期
- csv_file = open(r"test.csv", 'a', encoding="utf-8-sig", newline='')
- for p in range(5):#抓取前5页!!!抓取页数设置。
- params = {
- 'type': 'HSGTHDSTA','token': '70f12f2f4f091e459a279469fe49eca5',
- 'st': 'HDDATE,SHAREHOLDPRICE', 'sr': 3, 'ps': 50, 'rt': 51834660,
- 'p': p+1,
- 'filter': f"(MARKET in ('001','003'))(HDDATE>=^{start_rq}^ and HDDATE<=^{end_rq}^)"
- }
- get_json(params, csv_file)
- csv_file.close()
复制代码
|
|