node.js - NodeJS: Parsing HTML HTML and inline SVG graphics with Cheerio -


i developing node expressjs application, shall crawl html document, containing inline svg structure (svg html tag, defining svg graphic).

this svg structure contains lot "subtags" of type text, attributes inner text want extract of, using cheerio. unfortunately node application crashes, once gets reading attribute values of 1 of svg text attributes. find error message thrown below; unfortunately not meaningful. crashes both on windows , linux platforms.

using same selectors pure jquery , js in real browser environment, extract data working fine, seems cheerio. there maybe way of parsing inline svg structures?

error message:

npm err! windows_nt 10.0.15063 npm err! argv "<path node executable>" "<path node modues>\\npm\\bin\\npm-cli.js" "start" npm err! node v6.11.2 npm err! npm  v4.1.1 npm err! code elifecycle npm err! myapp@0.0.0 start: `node ./bin/www` npm err! exit status 1 npm err! npm err! failed @ myapp@0.0.0 start script 'node ./bin/www'. npm err! make sure have latest version of node.js , npm installed. [...] 

i found out reason failing lies within implementation, not in cheerio. implementation assumed real browser dom; of course that's not case on nodejs.

in case, had array sorting closure

jquery(selector).toarray().sort(function(a, b){         var aval = parseint(a.getattribute(attrname)),             bval = parseint(b.getattribute(attrname));         return aval - bval; }) 

which worked fine within real browser , real jquery, failed on nodejs using cheerio.

i rewrote code "re-jqueryfy" selected element within sorting closure, using jquery(a).attr(attrname), instead of a.getattribute(attrname):

jquery(selector).toarray().sort(function(a, b){     var aval = parseint(jquery(a).attr(attrname)),         bval = parseint(jquery(b).attr(attrname));     return aval - bval; }); 

i guess reason lies within nodejs itself, not cheerio, since there no dom available, selectable elements supporting getattribute function.


Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -