W
W
wufapexef2017-10-06 04:35:42
JavaScript
wufapexef, 2017-10-06 04:35:42

How to parse HTML with libxmljs?

I want to display the content of one node.

axios.get('example.com')
  .then((res) => {
    let xmlDoc = libxmljs.parseXml(res.data)
    let gchild = xmlDoc.get('//*[@id="wrap"]/div[2]/div/div[2]/div[3]/article/header/h1')
    console.log(gchild.text())
  })

Throws an error
{ Error: Extra content at the end of the document

    at Object.module.exports.fromXml (/home/***/Documents/WORK/SCRAPE-BOTS/axios-test/node_modules/libxmljs/lib/document.js:168:21)
    at axios.get.then (/home/nman/Documents/WORK/SCRAPE-BOTS/axios-test/index.js:15:27)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7) domain: 1, code: 5, level: 3, column: 2, line: 1 }

Is it possible to parse HTML with this bible?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stalker_RED, 2017-10-06
@Stalker_RED

Error: Extra content at the end of the document
Have you checked what's in there?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question