Puppeteer:puppeteer open a url without protocol Error

现象

无法打开无协议的网址

await page.goto("www.baidu.com");

原因

puppeteer open a url without protocol error

解决办法

const urlPackage = require("url");
//try fix without protocol url
if (this.params.Url.indexOf("http") == -1 && this.params.Url.indexOf("www") >= 0) 
{
    this.params.Url = urlPackage.format({
    protocol: "https",
    pathname: this.params.Url
    });
}

你可能感兴趣的:(Puppeteer:puppeteer open a url without protocol Error)