主要是发生在
URL 的拼接上
import urllib.request as ur
import os
import csv
import time
#
with open('../../DATA/over-the-counter_market.csv',newline="") as csvfile:
rows = csv.DictReader(csvfile)
for row in rows:
url = 'http://www.twse.com.tw/exchangeReport/FMNPTK?response=csv&stock
No
code = row['有价证券代号']
s = url + code
f = ur.urlopen(s)
with open(code+'.csv', 'wb') as out_file:
data = f.read().decode(f.headers.get_content_charset())
out_file.write(bytes(data, 'UTF-8'))
out_file.close()
print(s)
time.sleep(10)
其实我有试过 完整的URL http://www.twse.com.tw/exchangeReport/FMNPTK?response=c
sv
但是改成 URL 的拼接 虽然有产生2330.csv 但资料是空的 只有在完整的URL 资料才会写
入
请问大大们这个状况是我拼接字串有问题吗还是???