Python取页面源代码

取页面源代码

点击查看代码
#打开一个网址
from urllib.request import urlopen
url="http://www.baidu.com"

res=urlopen(url)

# print(res.read().decode("utf-8"))#拿到的是网页源代码
#
with open("mybaidu.htm",mode="w",encoding="utf-8")as f:
    f.write(res.read().decode("utf-8"))
posted @ 2021-11-04 14:27  Awindow  阅读(86)  评论(0编辑  收藏  举报