First
項目地址:Crawler-for-Github-Trending
項目中基本每一句代碼都寫有註釋(因爲就這麼幾行😂),適合對Node爬蟲感興趣的同學入入門。
Introduction
50 lines, minimalist node crawler for Trending.
一個50行的node爬蟲,一個簡單的 axios, express, cheerio 體驗項目。
Usage
首先保證電腦已存在node環境,然後
1.拉取本項目
git clone https://github.com/ZY2071/Crawler-for-Github-Trending.git
cd Crawler-for-Github-Trending
npm i
node index.js
2.或者下載本項目壓縮包,解壓
cd Crawler-for-Github-Trending-master // 進入項目文件夾
npm i
node index.js
Examples
當啓動項目後,可以看到控制檯輸出
Listening on port 3000!
此時打開瀏覽器,進入本地服務 http://localhost:3000/daily
http://localhost:3000/time-language // time表示週期,language代表語言 例如:
http://localhost:3000/daily // 代表今日 可選參數:weekly,monthly
http://localhost:3000/daily-JavaScript // 代表今日的java分類 可選參數:任意語言
稍微等待即可看到爬取完畢的返回數據:
[
{
"title": "lib-pku / libpku",
"links": "https://github.com/lib-pku/libpku",
"description": "貴校課程資料民間整理",
"language": "JavaScript",
"stars": "14,297",
"forks": "4,360",
"info": "3,121 stars this week"
},
{
"title": "SqueezerIO / squeezer",
"links": "https://github.com/SqueezerIO/squeezer",
"description": "Squeezer Framework - Build serverless dApps",
"language": "JavaScript",
"stars": "3,212",
"forks": "80",
"info": "2,807 stars this week"
},
...
]
More
本項目僅供爬取體驗,每次訪問都會實時爬取數據,所以數據返回速度會比較慢,實際操作應該是定時爬取數據然後將數據存進數據庫,數據從數據庫返回從而提高數據返回效率。
但項目很基礎,可以作爲以上各個node模塊最基礎的練手使用,希望可以幫到大家 😀