标签:write nbsp 收藏 自动 sel 后端 http gif link
偶然看到收藏一下
const puppeteer = require(‘puppeteer‘);
const fs = require(‘fs‘);
(async () => {
const browser = await puppeteer.launch({
headless: true
})
const page = await browser.newPage();
await page.goto(‘https://juejin.im‘);
await page.waitFor(1000);
await page.evaluate(async () => {
window.scrollTo(0,document.querySelector(‘.entry-list‘).scrollHeight);
});
await page.waitFor(500);
await page.evaluate(async () => {
window.scrollTo(0,document.querySelector(‘.entry-list‘).scrollHeight);
});
await page.waitFor(500);
const res = await page.evaluate(async () => {
window.scrollTo(0,document.querySelector(‘.entry-list‘).scrollHeight)
window.scrollTo(0,document.querySelector(‘.entry-list‘).scrollHeight)
return [].map.apply(document.querySelectorAll(‘.info-row.title-row .title‘),[v => ({
title:v.innerText,
link:v.href,
})])
});
fs.writeFileSync(‘juejin.txt‘,JSON.stringify(res));
browser.close();
})()
标签:write nbsp 收藏 自动 sel 后端 http gif link
原文地址:https://www.cnblogs.com/sugartang/p/11631720.html