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,24 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>测试</title>
</head>
<body>
<h2>测试测hi是</h2>
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
<li>6</li>
<li>7</li>
<li>8</li>
<li>9</li>
<li>10</li>
</ul>
</body>
</html>

View File

@@ -0,0 +1,33 @@
// var { test, hello } = require("./utils");
// var request = require("request");
// request('https://www.baidu.com/', function (error, response, body) {
// console.log(body);
// });
// console.log(test());
// console.log(hello());
// console.log("你好");
// var http = require('http');
// var fs = require('fs');
// http.createServer(function(req, res){
// var html = fs.readFileSync("./index.html");
// res.writeHead(200, {'Content-Type': 'text/html; charset=utf-8'});
// res.end(html.toString());
// }).listen(8080);
const fs = require('fs');
var readStream = fs.createReadStream('index.html');
var writeStream = fs.createWriteStream("1.png");
//覆盖原有数据
readStream.pipe(writeStream);
console.log("程序执行完毕");

View File

@@ -0,0 +1,18 @@
{
"name": "2021-11-17",
"version": "1.0.0",
"description": "npm学习",
"main": "index.js",
"scripts": {
"start": "node-dev index.js",
"pc": "node-dev src/pc.js"
},
"author": "bmy",
"license": "ISC",
"dependencies": {
"axios": "^0.24.0",
"cheerio": "^1.0.0-rc.10",
"iconv-lite": "^0.6.3",
"request": "^2.88.2"
}
}

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);
}

View File

@@ -0,0 +1,11 @@
class utils {
test () {
return "test"
}
hello() {
return "hello"
}
}
module.exports = new utils();