-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
80 additions
and
146 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
})(); | ||
})(); |
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Oops, something went wrong.