first commit

This commit is contained in:
编码猿
2024-09-27 02:06:13 +08:00
commit 852d94fbb9
36760 changed files with 3274413 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
module.exports = {
url: 'http://www.netbian.com/'
}

View File

@@ -0,0 +1,33 @@
const axios = require('axios');
const config = require("./config");
const iconv = require('iconv-lite');
class http {
constructor() {
this.http = axios.create({
baseURL: config.url,
timeout: 100000,
headers: {
"Cookie": "__yjs_duid=1_54d7d9761ff38fd500742b8c976378851637137358248; xygkqecookieclassrecord=%2C1%2C; Hm_lvt_14b14198b6e26157b7eba06b390ab763=1637137357,1637138134,1637138153,1637138272; xygkqecookieinforecord=%2C7-24028%2C7-24022%2C1-1%2C19-23857%2C11-23937%2C12-24000%2C; Hm_lpvt_14b14198b6e26157b7eba06b390ab763=1637144818",
"Host": "www.netbian.com",
"Referer": "http://www.netbian.com/index.htm",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36"
}
});
}
async get(params) {
var res = (await this.http.get(params.url, {
params: params.data,
responseType: params.type ? "arraybuffer" : "stream"
})).data;
if (params.type == "1") {
return iconv.decode(res,'gbk');
} else {
return res;
}
}
}
module.exports = new http();

View File

@@ -0,0 +1,87 @@
var http = require("./http");
const cheerio = require('cheerio');
const fs = require('fs');
const path = require('path');
var pagePicNums = 20;
var urlArr = [] // 存放每一页的网址
var urlIndex = 0;
var pagePicArr = [] // 存放当前页有多少列表需要爬取
var picIndex = 0;
for (var i = 1; i <= 10; i++) {
if (i == 1) {
urlArr.push("")
} else {
urlArr.push(`/index_${i}.htm`)
}
}
GetPageHtml();
async function GetPageHtml() {
console.log("GetPageHtml: ",urlArr[urlIndex]);
var res = await http.get({
url: urlArr[urlIndex],
data: {},
type: "1"
});
const $ = cheerio.load(res);
$(".list ul li").each(function() {
if ($(this).attr("class") != "nextpage") {
if (! ($(this).find("a").attr("href").includes("pic")) ) {
pagePicArr.push({
title: $(this).find("a img").attr("alt"),
url: $(this).find("a").attr("href")
})
}
}
});
console.log(pagePicArr);
GetPageInfo();
}
async function GetPageInfo() {
var res = await http.get({
url: pagePicArr[picIndex].url,
data: {},
type: "1"
});
const $ = cheerio.load(res);
createdImg($(".endpage .pic img").attr("src"))
if (picIndex <= pagePicArr.length - 1) {
picIndex += 1;
// 这一页爬结束了
if (picIndex > pagePicArr.length - 1) {
console.log(`当前第 ${urlIndex} 页结束,开始下一页 ${urlIndex + 1},下一页网址是:${urlArr[urlIndex]}`);
pagePicArr = [];
picIndex = 0;
urlIndex+=1;
GetPageHtml();
} else {
GetPageInfo();
}
}
}
async function createdImg(url) {
console.log(url);
var res = await http.get({
url: url,
data: {},
type: "2"
});
fs.writeFileSync(path.join(__dirname, `./img/${pagePicArr[picIndex]?.title}.jpg`), res);
}