首页 > 解决方案 > 使用jsdom运行脚本后如何抓取整个html

问题描述

如何在使用jsdom运行脚本后抓取整个 html 这是我要抓取的链接https://cma.org.sa/Market/imf/Pages/default.aspx

const fs = require('fs');
const jsdom = require('jsdom');
const { JSDOM } = jsdom;

const pdfUrl = 'https://cma.org.sa/Market/imf/Pages/default.aspx';

async function loadListView(){
    const dom = await JSDOM.fromURL(pdfUrl, {
        includeNodeLocations: true,
        pretendToBeVisual: true,
        runScripts: 'dangerously',
        resources: "usable",
    });
    dom.window.document.querySelectorAll('a').forEach(link => {
        console.log(link.href);
    });
    return dom;
}
loadListView()

我的代码只是在运行脚本之前获取 html。但我需要在运行所有脚本后 __scrape__ html 页面。谢谢。

标签: node.jsjsdom

解决方案


推荐阅读