初始化:
1.安裝了node
2.新建乙個資料夾
3.在該資料夾中初始化node應用
npm init
安裝依賴:
使用express框架
使用superagent庫:
superagent 是乙個輕量級、漸進式的請求庫,內部依賴 nodejs 原生的請求 api,適用於 nodejs 環境使用cheerio庫:
cheerio 是 nodejs 的抓取頁面模組,為伺服器特別定製的,快速、靈活、實施的 jquery 核心實現。適合各種 web 爬蟲程式。node.js 版的 jquery。
npm i express cheerio superagent -
d
**展示:
1.首先引入模組
const express =
require
("express"
)express()
const fs =
require
("fs"
)const superagent =
require
("superagent"
)const cheerio =
require
("cheerio"
)
2.宣告要爬的**url
const lagouurl =
"";const code =
"/?filteroption=3&sid=b87c46399fd24f618b97b395f945ab1b"
;
3.請求資料
superagent.
get(url)
.end
((err, res)
=>
else
})
4.分析資料
let
gethotdata
=(res,i)
=>
)// }})
return hotnews
}
5.儲存資料
fs.
writefilesync(`
$/data.json`
,json
.stringify
(listdata)
,'utf-8'
,(err)
=>
})
6.完整**
const express =
require
("express"
)express()
const fs =
require
("fs"
)const superagent =
require
("superagent"
)const cheerio =
require
("cheerio"
)const lagouurl =
"";const code =
"/?filteroption=3&sid=b87c46399fd24f618b97b395f945ab1b"
;get
("/"
,(req, key)
=>
/data.json`
,json
.stringify
(listdata)
,'utf-8'
,(err)
=>})
}clearinterval
(timer)
}else
else})
}},1000)}
)let
gethotdata
=(res,i)
=>
)// }})
return hotnews
}listen
(3000,(
)=> console.
log(
"啟動成功"
))
python 抓取拉勾網 攻略
廢話不多說,直接上 將資料存入mongdb import requests import pymongo import time import random mycon pymongo.mongoclient 127.0.0.1 27017 建立連線 mydb mycon lagou data 設定...
爬蟲 拉勾網 selenium
使用selenium進行翻頁獲取職位鏈結,再對鏈結進行解析 會爬取到部分空列表,感覺是網速太慢了,加了time.sleep 還是會有空列表 1 from selenium import webdriver 2import requests 3importre4 from lxml import et...
Python爬蟲獲取拉勾網招聘資訊
之前寫過乙份爬取拉勾網搜尋 資料分析 相關職位的文章拉勾網職位資訊爬蟲練習 最近入職了一家設計為主的公司,所以想做乙份關於 設計 的資料分析報告,發現直接跑原來的 會爬不到資料,所以稍微修改了一下。本篇主要記錄爬蟲 匯入使用的庫 import requests from bs4 import bea...