python编程篇之爬虫(一)
最简单的一个爬虫,爬取百度首页
import urllib
url = "http://www.baidu.com"
data = urllib.request.urlopen(url).read().decode('utf-8','ignore')
# print(data)
with open('E:/testFile/baidu.html', 'w', encoding='utf-8') as fh:
fh.write(data)
将爬取到的数据存储在本地文件上
本文介绍了一个简单的Python爬虫实例,演示如何使用urllib库抓取百度首页的内容,并将其保存为本地HTML文件。适合初学者理解爬虫的基本原理。
8万+

被折叠的 条评论
为什么被折叠?



