码迷,mamicode.com
首页 > 编程语言 > 详细

[python]抓取股票交易记录

时间:2015-01-06 23:09:57      阅读:259      评论:0      收藏:0      [点我收藏+]

标签:

#!/usr/bin/python
#DownByDate.py sh600115 2014-12-29 2015-3-15
#DownByDate.py stock_num start_date end_date

#http://stock.gtimg.cn/data/index.php?appn=detail&action=download&c=sh600115&d=20141229
#sh600115_2014-12-29.txt

import sys
import urllib
import datetime

def download_date(src_url,dest_file):
	download=urllib.FancyURLopener();
	download_page=download.open(src_url);
	savefile=file(dest_file,'wb+');
	while True:
		arr = download_page.read();
		if len(arr)==0:
			break;
		savefile.write(arr);
	savefile.flush();
	savefile.close();
	return

stock_code=sys.argv[1]
str_0='''http://stock.gtimg.cn/data/index.php?appn=detail&action=download&c='''
str_0=str_0 + stock_code + '&d='
date_start=datetime.datetime.strptime(sys.argv[2],'%Y-%m-%d')
if len(sys.argv)>3:
	date_end=datetime.datetime.strptime(sys.argv[3],'%Y-%m-%d')
else:
	date_end=date_start+datetime.timedelta(days=1)

while date_start<date_end:
	str_date=date_start.strftime('%Y%02m%02d')
	str_url=str_0+str_date
	str_file=stock_code + '_' + date_start.strftime('%Y-%02m-%02d') + '.txt'
	download_date(str_url,str_file)
	print str_file
	date_start=date_start+datetime.timedelta(days=1)

[python]抓取股票交易记录

标签:

原文地址:http://blog.csdn.net/adream307/article/details/42472313

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!