1.爬虫的用途
- 数据采集,用于个人或者公司进行分析数据
- 自动化操作流程
- 等等
2. 准备
- 安装python3.x环境
- 安装python编辑器工具,PyCharm,vscode等, 个人比较推荐VsCode
- 浏览器,比较推荐Chrome
3. 简单的一个示例
下面就是最简单把百度首页爬取到本地的例子
from urllib.request import urlopen
url = 'http://www.baidu.com'
with urlopen(url) as response:
with open('baidu.html', 'w', encoding='utf-8') as f:
f.write(response.read().decode('utf-8'))
response.close()