在现在这个信息爆炸的时代,要想高效的获取数据,爬虫是非常好用的。而用python做爬虫也十分简单方便,下面通过一个简单的小爬虫程序来看一看写爬虫的基本过程:
第一个是要使用的库,因为它是初学者最简单的程序,我们主要使用以下两个:
[En]
The first is the library to be used, because it is the simplest program for beginners, we mainly use the following two:
import requests //用于请求网页
import re //正则表达式,用于解析筛选网页中的信息
其中re是python自带的,requests库需要我们自己安装,在命令行中输入pip install requests即可。
然后随便找一个网站,小心不要试图抓取隐私敏感信息。这是一个表情包网站:
[En]
Then find a random website and be careful not to try to crawl privacy-sensitive information. Here is a meme site:
注意:Meme网站上的内容可以免费下载,所以爬虫程序只是简化了我们的逐点流程,并注意不要爬取付费资源。
[En]
Note: the content in the meme site here can be downloaded for free, so the crawler just simplifies our point-by-point process, and be careful not to crawl paid resources.
我们要做的就是通过爬虫把这些表情包下载到我们电脑里。