4.14

第⼀个爬虫

抓取百度网站源代码,并写入文件

from urllib.request import urlopen

resp = urlopen("http://www.baidu.com") # 打开 百度

# print(resp.read().decode("utf-8")) # 打印 抓取到 的内容

with open("baidu.html",mode="w", encoding="utf-8") as f: # 创建⽂件

f.write(resp.read().decode("utf-8")) # 保存在 ⽂件中

原文地址:https://www.cnblogs.com/zhaoyids/p/14902610.html