from urllib.request import urlopen #导包
url = "http://www.baidu.com" #爬虫网址
resp = urlopen(url) #打开网址并返回,也可以看作一个响应
with open("baidu.html",mode="w",encoding="utf-8") as f: #将结果保存到文件
f.write(resp.read().decode("utf-8")) #读取网页的页面源代码
执行结束便可以在同层目录下看到一个html文件