環(huán)境配置 (以mac電腦為例)
安裝chrome
-
安裝web scraper
-
安裝CouchDB
- 使用Homebrew安裝袋哼,在終端中輸入
brew install couchdb
- 在web scraper 設(shè)置 CouchDB
-
在瀏覽器找到Scraper圖示,點(diǎn)擊右鍵拍霜,選擇選項(xiàng)
image -
在storage settings界面峰锁,storage type 選擇couchDB
image - ditemap db 填寫
http://localhost:5984/scraper-sitemaps
Data db 填寫http://localhost:5984/
,點(diǎn)擊保存,不會(huì)有任何反應(yīng)拒炎,保存成功
image
-
- 使用Homebrew安裝袋哼,在終端中輸入
開始抓取內(nèi)容
-
準(zhǔn)備工作
開啟 couchDB
打開李笑來(lái)微博 https://weibo.com/bylixiaolai?is_all=1
-
使用command+alt+i打開web scraper
image
-
step 1 創(chuàng)建一個(gè)scraper任務(wù)
-
1.1 為scraper任務(wù)取一個(gè)名字,輸入要抓取的網(wǎng)址,點(diǎn)擊Create Sitemap創(chuàng)建一個(gè)任務(wù)
image -
1.2 介紹一個(gè)scraper菜單挨务,以及用處
image
-
-
step 2 添加一個(gè)id名為Element的選擇器
-
2.1 點(diǎn)擊Add new selector添加新的選擇器击你,出現(xiàn)選擇器默認(rèn)設(shè)置界面
image
image - 2.2 為選擇器取一個(gè)名字,在id輸入框輸入Element
- 2.3 為選擇器選一個(gè)類型谎柄,在type中選擇Element scroll down ,因?yàn)槲⒉╉?yè)面為下拉刷新顯示更多
- 2.4 為選擇器設(shè)置一個(gè)等待時(shí)間丁侄,Delay(ms)中輸入2000
- 2.5 選擇要抓取的元素 點(diǎn)擊1.Select;2.然后選擇要抓取的內(nèi)容朝巫,選擇兩個(gè)鸿摇,所有同類型的內(nèi)容都會(huì)變成紅色;3.點(diǎn)擊Done selecting 完成選擇
- 2.6 勾選擇Multiple
-
2.7 點(diǎn)擊Save selector保存選擇器
image
-
-
step 3 為Element選擇器添加一個(gè)子選擇器劈猿,用來(lái)抓取發(fā)布時(shí)間
-
3.1點(diǎn)擊Elemnet選擇器
image -
3.2 Element子選擇器配置界面
image -
3.3 點(diǎn)擊Add new selector添加子選擇器
image -
3.4 為子選擇器取名time,類型選擇text,點(diǎn)擊Select選擇頁(yè)面的時(shí)間拙吉,選擇的內(nèi)容底色是橙色的,
image -
3.5 點(diǎn)擊Save select保存
image
-
-
step 4 為Element選擇器添加一個(gè)子選擇器揪荣,用來(lái)抓取發(fā)布的內(nèi)容
-
4.1 點(diǎn)擊 Add new selector
image -
4.2 1.子選擇子取名Concent 2.類型為文本 3.點(diǎn)擊select 4.選擇要抓取的內(nèi)容 5.完成選擇
image -
4.3 保存選擇器
image
-
- 4.4 子選擇器內(nèi)容
![image](http://upload-images.jianshu.io/upload_images/3357352-a36d08b994f509ee.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
- 4.5 點(diǎn)擊_root回到主界面
![image](http://upload-images.jianshu.io/upload_images/3357352-a1c559bf3db5f61c.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
-
step 5 添加一個(gè)名Page的翻頁(yè)選擇器
-
5.1 微博頁(yè)面拖動(dòng)最底下筷黔,顯示下一頁(yè)
image -
5.2 點(diǎn)擊 add new selector
image -
5.3 1.頁(yè)面選擇器取名Page 2.類型選擇link 3.點(diǎn)擊select 4.選擇元素 span.list a
image - 5.3.2 修改選擇元素為
span.list li a
image -
5.4 勾選Mutiple
image -
5.5 保存之后界面
image
-
-
step 6 設(shè)置Page選擇器為Element選擇器的父選擇器
-
6.1 點(diǎn)擊Element選擇 Edit
image -
6.2 1. 按住command鍵之后選擇Page 2.保存
image -
6.3 選好之后
image
-
-
step 7 預(yù)覽
-
7.1 點(diǎn)擊Element選擇器的Element preview,預(yù)覽選擇選取的元素,被選擇的元素會(huì)變紅
image -
7.2 點(diǎn)擊Element選擇器Data preview
image -
7.3 數(shù)據(jù)預(yù)覽
image
-
-
step 8 正式抓取數(shù)據(jù)
-
8.1 點(diǎn)擊 Scrape
image - 8.2 設(shè)置請(qǐng)求下一個(gè)頁(yè)面的等待時(shí)間2000毫秒,打開頁(yè)面之后抓取的等待時(shí)間2000毫秒仗颈,點(diǎn)擊 Start scraping 開始抓取數(shù)據(jù)
image
-