玩
import urllib.request
import os, sys
import requests
import json
import re
import time
allfund_url = "http://fund.eastmoney.com/js/fundcode_search.js"
base_fund_image_url = "http://j3.dfcfw.com/images/JJJZ1/"
path = "20200725"
if os.path.exists(path):
pass
else:
os.mkdir( path, 0o0777 )
payload = {}
headers= {}
response = requests.request("GET", allfund_url, headers=headers, data = payload)
pattern = re.compile(r'\d{6}')
allfund_list = pattern.findall(response.text)
for code in allfund_list:
full_fund_image_url = base_fund_image_url + code +".png"
full_fund_image_name = path + '/' + code +".png"
print(full_fund_image_url)
print(full_fund_image_name)
try:
urllib.request.urlretrieve(full_fund_image_url , filename=full_fund_image_name)
except:
pass
'''
tmp_byte = response.text.encode('utf8')
tmp_str = str(tmp_byte, encoding = "utf8")
f = open('allfund.txt','w')
f.write(response.text)
f.flush()
f.close()
'''
'''
def SixNumber(str_number):
str_number=str(str_number)
while(len(str_number)<6):
str_number='0'+str_number
return str_number
'''