爬取百度网页源代码
爬虫:通过编写程序来获取到互联网上在资源
百度
需求:用程序模拟浏览器,输入一个网址,从该网址中获取到资源或内容
import urllib.request from urlopen
url="http://www.baidu.com"
req=urlopen(url)
with open("mybaidu.html",mode="w",encode="utf-8") as f:
f.write(req.read().decode("utf-8"));
print("over")
结果:
运行mybaidu.html可以看见爬取的百度网页