En scrapy de python hay un método para representar html en un navegador ( https://docs.scrapy.org/en/latest/topics/debug.html#open-in-browser ).
Actualmente estoy trabajando en el nodo y haciendo algo de raspado.
var req = http.request(options, function (res) { var chunks = []; res.on("data", function (chunk) { chunks.push(chunk); }); res.on("end", function () { var body = Buffer.concat(chunks); console.log(body.toString()); }); }); req.end();
Puedo obtener la página html raspada y me gustaría mostrarla en un navegador durante la depuración. ¿Cuál es la mejor manera de lograr esto en el nodo?
Como ejemplo, me gustaría establecer un punto de interrupción después de declarar el cuerpo y en REPL ejecutar algo como:
open_in_browser(body.toString())
como en scrapy.
Sin usar Puppeteer, podría usar chrome-launcher , luego usar chrome-remote-interface para interactuar con el puerto de depuración de Chrome, al que puede llamar un método para configurar el contenido de la página.
Por ejemplo,
function scrape_content() { const http = require('https') const options = { hostname: 'stackoverflow.com', port: 443, path: '/questions/71363220/is-there-a-way-to-open-html-in-a-browser-in-node', method: 'GET' } const req = http.request(options, function (res) { const chunks = [] res.on("data", chunk => chunks.push(chunk)) res.on("end", () => open_content_in_chrome(Buffer.concat(chunks).toString())) }) req.end() } scrape_content() async function open_content_in_chrome(content) { const ChromeLauncher = require('chrome-launcher') const chrome = await ChromeLauncher.launch() console.log(`Chrome debugging port running on ${chrome.port}`) const CDP = require('chrome-remote-interface') let client try { // connect to chrome debugging port client = await CDP({ port: chrome.port }) const { Page } = client const { frameId } = await Page.navigate({ url: 'about:blank' }) await Page.setDocumentContent({ frameId, html: content }) } catch (err) { console.error(err) } finally { if (client) { await client.close() } } }