nodejs node-html-parser can't read element's value

32 Views Asked by At

I am using node-html-parser module as below. The html is a simple

<div><input type="hidden" value="199,9" ></div>

The code is below:

   var { parse }   = require('node-html-parser');
   const body = '<div><input type="hidden" value="199,9" ></div>'
   var dom  = parse(body)
   console.dir(dom.querySelectorAll('div input')[0]);
   console.log(`log from  ` + dom.querySelectorAll('div input')[0] );
   console.log(`log from value ` + dom.querySelectorAll('div input')[0].value );

output is as

log from <input type="hidden" value="199,9" >
log from value undefined

the .value attribute returns undefined. How can I solve this problem? I just want to use node-html-parser module

EDIT:

If I run

console.dir(dom.querySelectorAll('div input')[0]);

I get something such as

rawAttrs: 'type="hidden" value="199,9" ',

I don't think it is possible to select the attribute alone with this module, so I will need to possibly regex.

0

There are 0 best solutions below