【问题标题】:Scrape local html file with playwright用剧作家刮取本地 html 文件
【发布时间】:2021-12-28 18:14:30
【问题描述】:

我正在尝试抓取本地 HTML 文件以获取页面标题我正在使用 playwright 节点 Js 库但我无法通过请帮我这里是代码

import playwright from "playwright";


async function main() {
    const browser = await playwright.chromium.launch({
        headless: true// setting this to true will not run the UI
    });
    
    const page = await browser.newPage();
    await page.goto('C:\Users\weske\Desktop\WebScraping\index.html');
    let title = await page.title();
    console.log(title);
    await page.waitForTimeout(5000); // wait for 5 seconds
    await browser.close();
}

main();
// error messages
(node:15800) UnhandledPromiseRejectionWarning: page.goto: net::ERR_FILE_NOT_FOUND at 
c:UsersweskeDesktopWebScrapingindex.html
=========================== logs ===========================
navigating to "c:UsersweskeDesktopWebScrapingindex.html", waiting until "load"
============================================================
    at main (file:///C:/Users/weske/Desktop/WebScraping/node.js:11:13)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:15800) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error 
originated either by throwing inside of an 
async function without a catch block, or by rejecting a promise which was not handled with 

.catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `-- 
 unhandled-rejections=strict` (see 
 https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
    (node:15800) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In 
 the future, promise rejections that are not handled will terminate the Node.js process with a 
non-zero exit code.

【问题讨论】:

    标签: node.js playwright


    【解决方案1】:

    始终确保将文件路径设置为这种格式

    `file://C:/Users/weske/Desktop/Webscraping/index.html`
    

    【讨论】:

      猜你喜欢
      • 2022-11-22
      • 2022-06-21
      • 2020-10-20
      • 2023-02-02
      • 2013-09-19
      • 1970-01-01
      • 2021-02-19
      • 2021-08-02
      • 2022-12-06
      相关资源
      最近更新 更多