环境配置 (以mac电脑为例)
安装chrome
-
安装web scraper
-
安装CouchDB
- 使用Homebrew安装,在终端中输入
brew install couchdb
- 在web scraper 设置 CouchDB
-
在浏览器找到Scraper图示,点击右键,选择选项
image -
在storage settings界面,storage type 选择couchDB
image - ditemap db 填写
http://localhost:5984/scraper-sitemaps
Data db 填写http://localhost:5984/
,点击保存,不会有任何反应,保存成功
image
-
- 使用Homebrew安装,在终端中输入
开始抓取内容
-
准备工作
开启 couchDB
-
使用command+alt+i打开web scraper
image
-
step 1 创建一个scraper任务
-
1.1 为scraper任务取一个名字,输入要抓取的网址,点击Create Sitemap创建一个任务
image -
1.2 介绍一个scraper菜单,以及用处
image
-
-
step 2 添加一个id名为Element的选择器
-
2.1 点击Add new selector添加新的选择器,出现选择器默认设置界面
image
image - 2.2 为选择器取一个名字,在id输入框输入Element
- 2.3 为选择器选一个类型,在type中选择Element scroll down ,因为微博页面为下拉刷新显示更多
- 2.4 为选择器设置一个等待时间,Delay(ms)中输入2000
- 2.5 选择要抓取的元素 点击1.Select;2.然后选择要抓取的内容,选择两个,所有同类型的内容都会变成红色;3.点击Done selecting 完成选择
- 2.6 勾选择Multiple
-
2.7 点击Save selector保存选择器
image
-
-
step 3 为Element选择器添加一个子选择器,用来抓取发布时间
-
3.1点击Elemnet选择器
image -
3.2 Element子选择器配置界面
image -
3.3 点击Add new selector添加子选择器
image -
3.4 为子选择器取名time,类型选择text,点击Select选择页面的时间,选择的内容底色是橙色的,
image -
3.5 点击Save select保存
image
-
-
step 4 为Element选择器添加一个子选择器,用来抓取发布的内容
-
4.1 点击 Add new selector
image -
4.2 1.子选择子取名Concent 2.类型为文本 3.点击select 4.选择要抓取的内容 5.完成选择
image -
4.3 保存选择器
image
-
- 4.4 子选择器内容
![image](http://upload-images.jianshu.io/upload_images/3357352-a36d08b994f509ee.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
- 4.5 点击_root回到主界面
![image](http://upload-images.jianshu.io/upload_images/3357352-a1c559bf3db5f61c.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
-
step 5 添加一个名Page的翻页选择器
-
5.1 微博页面拖动最底下,显示下一页
image -
5.2 点击 add new selector
image -
5.3 1.页面选择器取名Page 2.类型选择link 3.点击select 4.选择元素 span.list a
image - 5.3.2 修改选择元素为
span.list li a
image -
5.4 勾选Mutiple
image -
5.5 保存之后界面
image
-
-
step 6 设置Page选择器为Element选择器的父选择器
-
6.1 点击Element选择 Edit
image -
6.2 1. 按住command键之后选择Page 2.保存
image -
6.3 选好之后
image
-
-
step 7 预览
-
7.1 点击Element选择器的Element preview,预览选择选取的元素,被选择的元素会变红
image -
7.2 点击Element选择器Data preview
image -
7.3 数据预览
image
-
-
step 8 正式抓取数据
-
8.1 点击 Scrape
image - 8.2 设置请求下一个页面的等待时间2000毫秒,打开页面之后抓取的等待时间2000毫秒,点击 Start scraping 开始抓取数据
image
-