美文网首页
Puppeteer:puppeteer open a url w

Puppeteer:puppeteer open a url w

作者: 天山的虫 | 来源:发表于2020-04-13 14:54 被阅读0次

现象

无法打开无协议的网址

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 w

      本文链接:https://www.haomeiwen.com/subject/vuggmhtx.html