我想将网站的 HTML 写入我创建的文件,我很难解码为 utf-8,但它仍然会出现这样的错误,我使用print(data1)
并且正确打印了 html ,我使用的是python 3.5.0
import re
import urllib.request
city = input("city name")
url = "http://www.weather-forecast.com/locations/"+city+"/forecasts/latest"
data = urllib.request.urlopen(url).read()
data1 = data.decode("utf-8")
f = open("C:\\Users\\Gopal\\Desktop\\test\\scrape.txt","w")
f.write(data1)