Skip to content

Commit

Permalink
feat 提交同步
Browse files Browse the repository at this point in the history
  • Loading branch information
webkubor committed Jun 14, 2023
1 parent f5c1e4f commit 39d797a
Show file tree
Hide file tree
Showing 18 changed files with 80 additions and 146 deletions.
File renamed without changes.
File renamed without changes.
33 changes: 16 additions & 17 deletions getHtml.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
const puppeteer = require('puppeteer');
const cheerio = require('cheerio');

(async () => {
// 启动无头浏览器
const browser = await puppeteer.launch({
headless: "new"
})

const url = 'https://c12.onepy.top/proof/?enc=b46GoOCK7A3i6XvotpZKKrblTOZ5gxIctavsXULG67uXnFZvYdx5Nrq5u46xfOH13LrPazJKRqTmp7EUU9qUUg==#/index';

const browser = await puppeteer.launch();
const page = await browser.newPage();

// 等待页面加载和渲染完毕
await page.goto(url, {waitUntil: 'networkidle2'});

await page.emulateMedia('screen');
await page.pdf({path: '111111111.pdf', format: 'A4',scale: 0.7,margin:{top: '20px',left: '20px',bottom: '20px',right: '20px'}}); // create a PDF
// 导航到目标网页
await page.goto('https://c12.onepy.top/proof/?enc=b46GoOCK7A3i6XvotpZKKrblTOZ5gxIctavsXULG67uXnFZvYdx5Nrq5u46xfOH13LrPazJKRqTmp7EUU9qUUg==#/index');

// 等待网页加载完成
await page.waitForNavigation({ waitUntil: 'networkidle0' });

// 获取完整渲染后的 HTML
const html = await page.content();

// // 等待3秒
// await page.waitForTimeout(6000);
// 使用 Cheerio 解析 HTML
const $ = cheerio.load(html);

// // 截图并保存到本地
// await page.screenshot({ path: 'screenshot.png' });
// 查找 .brazil 元素并获取所有文本内容
const brazilText = $('.brazil').text();
console.log(brazilText);

// 关闭浏览器
await browser.close();
})();
})();
13 changes: 0 additions & 13 deletions index.html

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
9 changes: 1 addition & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,7 @@
"description": "",
"main": "index.js",
"scripts": {
"index": "node index",
"fetch": "node fetch",
"spider": "node spider",
"ip": "node getUserIp",
"url": "node transURLParams",
"fs": "node fileSteam",
"screen": "node screenshot",
"pdf": "node pdf"
"index": "node index"
},
"keywords": [
"screenshot",
Expand Down
39 changes: 0 additions & 39 deletions screenshot.js

This file was deleted.

Binary file added screenshot/test.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshot/yuque.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 5 additions & 4 deletions captureScreenshot.js → shortPicture.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
const puppeteer = require('puppeteer');

async function captureScreenshot(url, outputFilePath) {
const browser = await puppeteer.launch();
const browser = await puppeteer.launch({headless: true});
const page = await browser.newPage();
await page.goto(url, { waitUntil: 'networkidle0' }); // 等待页面加载完成

// 获取页面的整个高度和宽度
const bodyHeight = await page.evaluate(() => document.body.scrollHeight);
const bodyWidth = await page.evaluate(() => document.body.scrollWidth);
// const bodyWidth = await page.evaluate(() => document.body.scrollWidth);

// 设置视口大小和截图尺寸
await page.setViewport({ width: bodyWidth, height: bodyHeight });
await page.setViewport({ width: 1366, height: bodyHeight });
await page.screenshot({ path: outputFilePath, fullPage: true });

await browser.close();
}
const url = 'https://www.yuque.com/webkubor';

captureScreenshot('https://www.example.com', 'example.png')
captureScreenshot(url, 'screenshot/yuque.png')
.then(() => console.log('Screenshot captured'))
.catch(error => console.error(error));
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 39d797a

Please sign in to comment.