pa

var Nightmare = require("nightmare");
const fs = require("fs");
const open = function (page) {
var nightmare = Nightmare({
show: false,
executionTimeout: 1000 * 60 * 100,
waitTimeout: 1000 * 60 * 100,
});
nightmare
.goto(`https://china.findlaw.cn/laodongfa/shangyemimi/index_${page}.html`)
.wait(".footer-layout")
.evaluate(function () {
console.log("执行函数");
let list = document.querySelectorAll(".article-list")[0].children;
let s = "";
for (let i = 0; i < list.length; i++) {
try {
let href = list[i].children[0].href;
let text = list[i].children[1].children[0].innerText;
let reading =
list[i].children[1].children[1].children[1].textContent.match(
/\d+.\d+/
)[0];
s = s + `'${href}'-'${text}'-'${reading}'||`;
// arr.push({
// href: list[i].children[0].href,
// text: list[i].children[1].children[0].innerText,
// reading:
// list[i].children[1].children[1].children[1].textContent.match(
// /\d+.\d+/
// )[0],
// });
} catch (e) {}
}
return s;
})
.end()
.then(function (result) {
// console.log(result);
fs.appendFile("./log.text", result, (err) => {
if (err) throw err;
});
})
.catch(function (error) {
console.error("Search failed:", error);
});
};
function sleep(time) {
return new Promise((resolve) => setTimeout(resolve, time));
}
function run() {
let page = 1;
fs.writeFile("./log.text", "", (err) => {
if (err) throw err;
});
console.time("爬取耗时:");
for (page; page <= 37; page++) {
open(page);
sleep(3000);
}
console.timeEnd("爬取耗时:");
}
run();
posted @   lambertlt  阅读(7)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 25岁的心里话
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
点击右上角即可分享
微信分享提示