使用 Chrome 瀏覽器插件 Web Scraper 可以輕松實(shí)現(xiàn)網(wǎng)頁(yè)數(shù)據(jù)的爬取凡伊,不寫(xiě)代碼零渐,鼠標(biāo)操作,點(diǎn)哪爬哪系忙,還不用考慮爬蟲(chóng)中的登陸诵盼、驗(yàn)證碼、異步加載等復(fù)雜問(wèn)題。
Web Scraper 官網(wǎng)中的簡(jiǎn)介:
Web Scraper Extension (Free!)
Using our extension you can create a plan (sitemap) how a web site should be traversed and what should be extracted. Using these sitemaps the Web Scraper will navigate the site accordingly and extract all data. Scraped data later can be exported as CSV.
先看一下风宁,我用 web scaper 爬取到的數(shù)據(jù):
1. 知乎輪子哥粉絲
輪子哥有 54 萬(wàn)多粉絲洁墙,我只抓取了前 20 頁(yè)400條記錄
2.簡(jiǎn)書(shū)七日熱門(mén)數(shù)據(jù)
Web Scraper 抓取流程及要點(diǎn):
安裝Web Scraper插件后,三步完成爬取操作
1戒财、Create new sitemap(創(chuàng)建爬取項(xiàng)目)
2热监、選取爬取網(wǎng)頁(yè)中的內(nèi)容,點(diǎn)點(diǎn)點(diǎn)固翰,操作
3狼纬、開(kāi)啟爬取,下載CSV數(shù)據(jù)
其中最關(guān)鍵的是第二步骂际,兩個(gè)要點(diǎn):
- 先選中數(shù)據(jù)塊 Element疗琉,每塊數(shù)據(jù)我們?cè)陧?yè)面上取,都是重復(fù)的歉铝,選中 Multiple
- 在數(shù)據(jù)塊中再取需要的數(shù)據(jù)字段(上圖Excel中的列)
爬取大量數(shù)據(jù)的要點(diǎn)盈简,在于掌握分頁(yè)的控制。
分頁(yè)分為3種情況:
- URL 參數(shù)分頁(yè)(比較規(guī)整方式)
URL 中帶有分頁(yè)的 page 參數(shù)的太示,如:
https://www.zhihu.com/people/excited-vczh/followers?page=2
直接在創(chuàng)建sitemap時(shí)柠贤,Start URL中就可以帶上分頁(yè)參數(shù),寫(xiě)成這樣:
https://www.zhihu.com/people/excited-vczh/followers?page=[1-27388]
滾動(dòng)加載类缤,點(diǎn)擊“加載更多” 加載頁(yè)面數(shù)據(jù)
點(diǎn)擊分頁(yè)數(shù)字標(biāo)簽(包括“下一頁(yè)”標(biāo)簽)
注意臼勉,這里第2-3種可以歸為一類(lèi)方式,是異步加載的方式餐弱,大部分都可以轉(zhuǎn)為第1種的方式來(lái)處理宴霸。
這種方式分頁(yè)不太好控制。一般使用 Link 或 Element click 來(lái)實(shí)現(xiàn)分頁(yè)的操作膏蚓。
圖示 Web Scraper 操作步驟:
Web Scaper 使用體會(huì):
除了規(guī)整的分頁(yè)方式外瓢谢,其他分頁(yè)方式不好控制,不同的網(wǎng)站受頁(yè)面標(biāo)簽不同驮瞧,操作也不一樣氓扛。
因?yàn)橹苯幼ト№?yè)面顯示值,抓取數(shù)據(jù)規(guī)整度不太好论笔,需要 EXCEL 函數(shù)處理采郎。
如,簡(jiǎn)書(shū)七日熱門(mén)中文章發(fā)表時(shí)間狂魔,格式有好幾種尉剩。有一點(diǎn)網(wǎng)頁(yè)代碼基礎(chǔ)的上手很快,代碼才是王道啊毅臊。
特別是有點(diǎn)Python爬蟲(chóng)基礎(chǔ)的理茎,在選取頁(yè)面數(shù)據(jù)中很容易操作黑界、理解,發(fā)現(xiàn)操作中出現(xiàn)的問(wèn)題皂林。比起八爪魚(yú)朗鸠、火車(chē)頭等數(shù)據(jù)采集器,web scraper不需要下載軟件础倍,免費(fèi)烛占,無(wú)需注冊(cè),還很體會(huì)一點(diǎn)點(diǎn)代碼的操作沟启。當(dāng)然 web scraper 也有付費(fèi)的云爬蟲(chóng)忆家。
Web Scraper 還可以導(dǎo)入sitemap,把下面的這段代碼導(dǎo)入德迹,你就可以抓取到知乎輪子哥前20頁(yè)的粉絲:
{"startUrl":"https://www.zhihu.com/people/excited-vczh/followers?page=[1-20]","selectors":[{"parentSelectors":["_root"],"type":"SelectorElement","multiple":true,"id":"items","selector":"div.List-item","delay":""},{"parentSelectors":["items"],"type":"SelectorText","multiple":false,"id":"name","selector":"div.UserItem-title a.UserLink-link","regex":"","delay":""},{"parentSelectors":["items"],"type":"SelectorText","multiple":false,"id":"desc","selector":"div.RichText","regex":"","delay":""},{"parentSelectors":["items"],"type":"SelectorText","multiple":false,"id":"answers","selector":"span.ContentItem-statusItem:nth-of-type(1)","regex":"","delay":""},{"parentSelectors":["items"],"type":"SelectorText","multiple":false,"id":"articles","selector":"span.ContentItem-statusItem:nth-of-type(2)","regex":"","delay":""},{"parentSelectors":["items"],"type":"SelectorText","multiple":false,"id":"fans","selector":"span.ContentItem-statusItem:nth-of-type(3)","regex":"","delay":""}],"_id":"zh_vczh"}
PS, Web Scraper 資料教程
官網(wǎng)中的視頻教程
http://webscraper.io/tutorials知乎@陳大欣 的回答 中寫(xiě)了詳細(xì)的步驟芽卿,并錄制了視頻教程。
這個(gè)問(wèn)題來(lái)源 零基礎(chǔ)如何學(xué)爬蟲(chóng)技術(shù)胳搞? @陳大欣 在文章中把 Excel 爬蟲(chóng)卸例,web scraper,代碼爬蟲(chóng)做了比較分析肌毅。