3 回答

TA貢獻1829條經(jīng)驗 獲得超6個贊
那么,你應(yīng)該縮進這個:
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條經(jīng)驗 獲得超3個贊
代碼是正確的,只是存在縮進問題。下面的代碼應(yīng)該在for循環(huán)的內(nèi)部
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)
而下面的代碼應(yīng)該在外層的for循環(huán)中
sys.stdout.flush()
添加回答
舉報