Puppeteer -(Page.navigate:无法导航到无效 URL)

Div*_*Sah 5 javascript node.js web-scraping cheerio puppeteer

在这里,我有一个数组列表我的 URL 来自数组

网址:

url= result[urls]
console.log(url)
Run Code Online (Sandbox Code Playgroud)

输出:

books.toscrape.com/catalogue/a-light-in-the-attic_1000/index.html
Run Code Online (Sandbox Code Playgroud)

当我使用这个时:

 await page.goto('"http://' + url + '"');
Run Code Online (Sandbox Code Playgroud)

我收到类似这样的错误:

 Error: Protocol error (Page.navigate): Cannot navigate to invalid URL
Run Code Online (Sandbox Code Playgroud)

注意:当我用这个代替时:

await page.goto("http://books.toscrape.com/catalogue/soumission_998/index.html");
Run Code Online (Sandbox Code Playgroud)

然后就可以了

有人对此有想法吗?如何解决这个错误:)

小智 1

如果 SMTH 答案不起作用。你可以await page.goto(`https://${url}`);尝试一下。