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,4 @@
module.exports = {
url: 'https://pic.netbian.com/4kmeinv/',
picUrl: 'https://pic.netbian.com'
}

View File

@@ -0,0 +1,26 @@
const axios = require('axios');
const iconv = require('iconv-lite');
const cheerio = require('cheerio');
class Http {
constructor() {
this.instance = axios.create({
timeout: 10000,
headers: {}
});
}
async get (params) {
let res = await this.instance.get(params.url, {
responseType: params.type == 1 ? "arraybuffer" : "stream"
});
if (params.type == 1) {
return cheerio.load(iconv.decode(res.data, 'gbk'));
}
return res.data;
}
}
module.exports = new Http();

View File

@@ -0,0 +1,73 @@
const http = require('./http');
const config = require('./config');
const fs = require('fs');
let urlArr = [] // 存放被请求的页面地址
let urlArrIndex = 0; // 默认从第几页开始爬
let pageArr = [] // 存放每一页的20条li数据
let pageArrIndex = 0 // 默认爬第几页的第几个图片
for (let i = 1; i <= 10; i++) {
if (i == 1) {
urlArr.push(`${config.url}index.html`)
} else {
urlArr.push(`${config.url}index_${i}.html`)
}
}
async function getUrlArr() {
let $ = await http.get({
url: urlArr[urlArrIndex],
type: 1
});
$(".slist li").each(function () {
pageArr.push({
title: $(this).find("b").text(),
img: config.picUrl+$(this).find("img").attr("src"),
url: config.picUrl+$(this).find("a").attr("href")
})
});
getPageArr()
}
async function getPageArr() {
console.log(`已获取第 ${urlArrIndex + 1}页, 的第几张 ${pageArrIndex + 1}`)
let $ = await http.get({
url: pageArr[pageArrIndex].url,
type: 1
});
downImg(config.picUrl + $(".photo-pic img").attr("src"))
}
async function downImg(url) {
let res = await http.get({
url: url,
type: 2
});
res.pipe(fs.createWriteStream(`img/${fileName()}.jpg`));
pageArrIndex += 1;
if (pageArrIndex <= 19) {
getPageArr()
} else {
urlArrIndex += 1;
if (urlArrIndex < 10) {
pageArrIndex = 0;
pageArr = [];
getUrlArr()
}
}
}
function fileName() {
return `${Math.random() * 1000000}${Date.parse(new Date())}`
}
getUrlArr()