# -*- coding:utf-8 -*- import time import requests
defdownload_file(url,local_filename): r = requests.get(url, stream=True,verify = False) withopen(local_filename, 'wb') as f: for chunk in r.iter_content(chunk_size=1024): if chunk: # filter out keep-alive new chunks f.write(chunk) f.flush() return local_filename
savePath = 'E://12306/' url = 'https://kyfw.12306.cn/otn/passcodeNew/getPassCodeNew?module=login&rand=sjrand&0.7923694306518883' for i in xrange(0x7fffffff): print download_file(url, savePath + str(i+1) +'.jpg') time.sleep(1) #休眠一秒