相关疑难解决方法(0)

木偶-协议错误(Page.navigate):目标已关闭

如您在下面的示例代码中所看到的,我将Puppeteer与Node中的一组工作人员一起使用,以通过给定的URL运行多个网站截图请求:

const cluster = require('cluster');
const express = require('express');
const bodyParser = require('body-parser');
const puppeteer = require('puppeteer');

async function getScreenshot(domain) {
    let screenshot;
    const browser = await puppeteer.launch({ args: ['--no-sandbox', '--disable-setuid-sandbox', '--disable-dev-shm-usage'] });
    const page = await browser.newPage();

    try {
        await page.goto('http://' + domain + '/', { timeout: 60000, waitUntil: 'networkidle2' });
    } catch (error) {
        try {
            await page.goto('http://' + domain + '/', { timeout: 120000, waitUntil: 'networkidle2' });
            screenshot = await page.screenshot({ type: 'png', encoding: 'base64' });
        } …
Run Code Online (Sandbox Code Playgroud)

node.js web-scraping node-cluster google-chrome-headless puppeteer

5
推荐指数
5
解决办法
5819
查看次数

Puppeteer 协议错误 (Runtime.callFunctionOn):目标已关闭

我是 javascript 和 nodejs 新手

我正在尝试使用 google puppeteer 使用 node.js 生成 PDF 表。

我遵循了 YouTube 教程,下面的代码与教程中使用的相同。注意:我不相信以下代码。

我使用了一个示例 HTML 模板,我从 json 文件填充数据。

    const puppeteer = require('puppeteer');
    const fs = require('fs-extra');
    const hbs = require('handlebars');
    const path = require('path');
    const data = require('./stressData2.json');

    const compile = async function(templateName, data){
        const filePath = await path.join(process.cwd(), 'templates', `${templateName}.hbs`);
        const html = await fs.readFile(filePath, 'utf-8');
        return await hbs.compile(html)(data);
    };

    (async function(){
        try{
            const browser = await puppeteer.launch();
            const page = await browser.newPage();
            const content = …
Run Code Online (Sandbox Code Playgroud)

javascript google-chrome node.js node-modules puppeteer

5
推荐指数
1
解决办法
4325
查看次数