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,9 @@
var http = require('http');
var fs = require('fs');
http.createServer(function(req, res){
res.writeHead(200, {'Content-Type': 'text/html; charset=utf-8'});
var html = fs.readFileSync("./index.html");
res.end(html.toString());
}).listen(3000)

View File

@@ -0,0 +1,12 @@
<!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>Document</title>
</head>
<body>
<h2>哈哈哈</h2>
</body>
</html>

View File

@@ -0,0 +1,3 @@
var utils = require("./utils");
utils.test()

View File

@@ -0,0 +1,16 @@
{
"name": "2021-08-10",
"version": "1.0.0",
"description": "nodejs学习",
"main": "index.js",
"scripts": {
"start": "node index.js",
"http": "node-dev http.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"axios": "^0.21.1",
"cheerio": "^1.0.0-rc.10"
}
}

View File

@@ -0,0 +1,98 @@
const axios = require('axios');
const cheerio = require('cheerio');
const url = require("url");
const fs = require("fs");
// 存放每个页面的
var urlArr = [];
// 存放详情地址的
var infoArr = [];
// 详情页需要被下载的图片数据
var infoImgArr = []
var infoImgIndex = 0;
var infoIndex = 0;
var pageIndex = 0;
for (var i = 1; i <= 12; i++) {
urlArr.push(`https://www.mmav.me/forum-12-${i}.htm`);
}
getHTML()
/**
* 用来爬每一页的 假设 1 ~ 100
*/
async function getHTML() {
console.log(`1: getHTML 的 pageIndex 为:${pageIndex}`);
var result = await axios.get(urlArr[pageIndex]);
const $ = cheerio.load(result.data);
$(".cont .list_info a").each(function () {
infoArr.push("https://www.mmav.me/" + $(this).attr("href"))
});
getInfo()
}
async function getInfo() {
console.log(`2: getInfo 的 infoIndex 为:${infoIndex}`);
var result = await axios.get(infoArr[infoIndex]);
const $ = cheerio.load(result.data);
$(".imglist li a img").each(function () {
var bigImg = $(this).attr("data-original")
bigImg = bigImg.replace(/_t\./g, ".")
infoImgArr.push("https://www.mmav.me" + bigImg)
});
downImg()
}
async function downImg() {
console.log(`3: downImg 的 infoImgIndex 为:${infoImgIndex},被下载的图片地址为:${infoImgArr[infoImgIndex]}`);
axios({
method: 'get',
url: infoImgArr[infoImgIndex],
responseType: 'stream'
}).then(function (response) {
response.data.pipe(fs.createWriteStream(`img/${imgName(infoImgArr[infoImgIndex])}`));
infoImgIndex += 1
if (infoImgIndex < infoImgArr.length) {
downImg()
}
else {
infoImgIndex = 0;
infoImgArr = [];
infoIndex += 1
if (infoIndex < infoArr.length) {
getInfo()
}
else {
infoIndex = 0
infoArr = []
pageIndex += 1
if (pageIndex < urlArr.length) {
getHTML()
} else {
console.log("所有页数下载完成");
}
}
}
});
}
function imgName(urlPath) {
return url.parse(urlPath).path.split("/pic/")[1].split("/")[1]
}
// https://www.mmav.me/uploadfile/pic/20210430/467_12_t8JXXgLYcEgtD5IM3kOw.jpg
// https://www.mmav.me/uploadfile/pic/20210430/467_12_t8JXXgLYcEgtD5IM3kOw.jpg
// https://www.mmav.me/uploadfile/pic/20210430/467_12.JXXgLYcEgtD5IM3kOw.jpg

View File

@@ -0,0 +1,9 @@
const url = require("url")
function imgName(urlPath) {
return url.parse(urlPath).path.split("/pic/")[1].split("/")[1]
}
var a = imgName("https://www.mmav.me/uploadfile/pic/20210430/467_25_ZaWXZk0VFxCGE6GHU6lr.jpg");
console.log(a)

View File

@@ -0,0 +1,8 @@
class Utils {
test () {
console.log("测试工具函数");
}
}
module.exports = new Utils();

View File

@@ -0,0 +1,53 @@
Node.js
作用:写特效
写功能
运行在前端(后端)浏览器上(服务器上)的脚本语言
Node.js 不是框架,也不是新的语言
只是一个运行环境而已
c++ 帮你js和系统进行交互
v8 引擎 运行js的
js
|
nodejs
|
c++
|
系统
npm: Node.js 自带的包(插件)管理工具
npm installi 插件名
npm i 初始化项目
npm init
install 插件分为三种环境
安装到项目中
开发阶段 devDependencies
npm i --save-dev-D 插件名
正式阶段 dependencies
npm i --save-S 插件名
安装到系统全局
npm i -g 插件名
npm run 命令名字
npm start
Go
deno
Rust
TypeScript
爬虫