1.關(guān)于 NodeJS 簡單代理池
前面基本建設(shè)可以參考以前的文章:
拾肆-NodeJS簡單代理池(起)
拾捌-NodeJS簡單代理池(轉(zhuǎn))
1.1 本次更新綜述
本次只是在看到很多代理服務(wù)器上面醇滥,高匿代理都是以9999端口開放的,思考是否可以自己爬出代理阅虫?
1.2 新增函數(shù)
其實(shí)思路很簡單颓帝,就是隨機(jī)一個(gè) IP 窝革,然后如果該 IP 能順利通過代理驗(yàn)證就直接放進(jìn)代理池上面,完整代碼如下:
reqRandPro(objCTLSave, funCB) {
const that = this;
// 處理函數(shù)
let funGoRandSpy = (strRandProxy, funCB) => {
// 上網(wǎng)看到很多高匿的代理都是9999端口的虐译,就嘗試一下隨機(jī)測試網(wǎng)上所有9999端口唄
let strProxy = 'http://' + strRandProxy + ':9999';
request.get('https://www.baidu.com').timeout({ response: that.intTimeout, deadline: that.intTimeout * 3 }).use(superagentCheerio).proxy(strProxy).set(that.objHeader).then((res) => {
let objProxyForSave = { u: strRandProxy, p: '9999' };
// 通過之后就進(jìn)行保存
objCTLSave.saveOneProxy(objProxyForSave, () => {});
console.log(' ' + strProxy + ' 測試居然通過菱蔬!');
funCB(null, true);
}).catch((err) => {
funCB(null, true);
});
};
let arrRandProxy = [];
for (let intJ = 0; intJ < 100; intJ++) {
// 生成100個(gè)隨機(jī) IP
let strTestingIP = (Math.floor(Math.random() * 255)).toString() + "." + (Math.floor(Math.random() * 255)).toString() + "." + (Math.floor(Math.random() * 255)).toString() + "." + (Math.floor(Math.random() * 255)).toString();
arrRandProxy.push(strTestingIP);
}
// 異步測試
async.eachLimit(arrRandProxy, 5, funGoRandSpy, (err) => {
funCB(err, true);
});
}
1.3 再之后
其實(shí)我也想不出什么其他辦法可以了拴泌,準(zhǔn)備吃飯了。
2.關(guān)于 Python 捉取網(wǎng)頁內(nèi)容
在前期的內(nèi)容上箭昵,思來想去回季,如果根據(jù)捉取的鏈接再重新捉取內(nèi)容好像很麻煩,思來想去泡一,還是覺得直接在捉取的時(shí)候直接捉內(nèi)容比較好吧鼻忠。
2.1 依靠是什么帖蔓?
Beautiful Soup 文檔
所謂有事沒事看文檔塑娇,是做學(xué)術(shù)的人應(yīng)該有的態(tài)度。
2.2 我做了什么哨啃?
我前期已經(jīng)做倒請(qǐng)求了每一個(gè)頁面:
廿壹-爬 URL 棘催、Python 異步 、Supervisor 安裝配置等事宜
我只是在爬鏈接時(shí)順便把所有 <p> 的內(nèi)容加起來而已邑跪,函數(shù)如下:
def AddPContent(self, arrTagP):
# print(' 成功爬了一個(gè)網(wǎng)站')
strPContent = ''
for eleP in arrTagP:
strPContent += eleP.get_text()+' '
dictNewContent = self.AnEmptyContentEle()
dictNewContent['ct']=strPContent
if len(strPContent)>20:
# print(' 成功爬了一個(gè)網(wǎng)站')
self.objMongoDB.InsertOne('sampledb', dictNewContent)
# else :
# print(' 字?jǐn)?shù)不夠不保存')
這樣我就能把內(nèi)容都放到數(shù)據(jù)庫中了画畅!很開心轴踱!
2.3 后續(xù)要干嘛谚赎?
其實(shí)我覺得我還有三個(gè)東西要做,不知道假期結(jié)束前能不能完成:
- 做一個(gè) Django控制以及判斷情緒是否正確
- 根據(jù)關(guān)鍵字生成決策樹雳灵,看對(duì)一篇文章情緒是正面還是負(fù)面
- 捉取數(shù)據(jù)時(shí)看能否捉取 JS 內(nèi)容