Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

93
Views
Cómo serializar HTML sin etiquetas de cabeza y cuerpo usando jsdom

Quiero borrar algunas etiquetas de un documento html así:

 const { JSDOM } = require('jsdom'); function clearAnchorTags(pDom: JSDOM) { if (typeof pDom === 'string') { pDom = new JSDOM(pDom); } // Get all anchor tags from dom for (const anchorTag of pDom.window.document.querySelectorAll('a')) { for (const child of anchorTag.children) { if (child.nodeName === 'EM') { const node = pDom.window.document.createTextNode(child.textContent); anchorTag.replaceChild(node, child); } if (child.nodeName === 'B') { const node = pDom.window.document.createTextNode(child.textContent); anchorTag.replaceChild(node, child); } if (child.nodeName === 'U') { const node = pDom.window.document.createTextNode(child.textContent); anchorTag.replaceChild(node, child); } } } // return as string just as we received it -- also replace   with space return pDom.serialize().replace(/ /g, ' '); }

El problema parece ser el método serialize() aquí al final, ya que devuelve un documento HTML con todas las funciones.

Lo necesito sin las etiquetas <html>, <head> and <body> . Solo necesito un fragmento de HTML.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Resolví mi problema usando

 return pDom.window.document.body.innerHTML.replace(/&nbsp;/g, ' ');
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!