import urllib.request url = 'http://www.baidu.com/' response = urllib.request.urlopen(url) data = response.read() str_data = data.decode('utf_8') # print(str_data) with open('baidu.html','w',encoding='utf_8') as f: f.write(str_data)