3 回答

TA貢獻1829條經驗 獲得超6個贊
那么,你應該縮進這個:
texts=requests.get(url)
text_utf=texts.text.encode("utf=8")
if not os.path.exists("Data/Html_Data/{}".format(year)):
os.makedirs("Data/Html_Data/{}".format(year))
with open("Data/Html_Data/{}/{}.html".format(year,month),"wb") as output:
output.write(text_utf)

TA貢獻1875條經驗 獲得超3個贊
代碼是正確的,只是存在縮進問題。下面的代碼應該在for循環的內部
texts=requests.get(url)
text_utf=texts.text.encode("utf=8")
if not os.path.exists("Data/Html_Data/{}".format(year)):
os.makedirs("Data/Html_Data/{}".format(year))
with open("Data/Html_Data/{}/{}.html".format(year,month),"wb") as output:
output.write(text_utf)
而下面的代碼應該在外層的for循環中
sys.stdout.flush()
添加回答
舉報