Parsing HTML/XML with XPath in node.js -


i'm trying write xpath statement fetch contents of each row in table, when 2nd column of each row not set "tba". page working off this page. new using xpath.

i've come following statement, i've managed test (or appears successful anyway) online xpath tester, have been unable figure out how apply in node.js:

//*[@id="body_column_left"]/div[4]/table/tbody/tr/[not(contains(./td[2], 'tba'))]

this attempt below, i've tried variations can't validate valid xpath statement , result i've been lost in not helpful stack traces:

var fs = require('fs'); var xpath = require('xpath'); var parse5 = require('parse5'); var xmlser = require('xmlserializer'); var dom = require('xmldom').domparser; var request = require('request');  var gethtml = function (url, callback) {     request(url, function (error, response, body) {         if (!error && response.statuscode == 200) {             return callback(body) // return html         }     }) }  gethtml("http://au.cybergamer.com/pc/csgo/ladder/scheduled/", function (html) {     var parser = new parse5.parser();     var document = parser.parse(html.tostring());     var xhtml = xmlser.serializetostring(document);     var doc = new dom().parsefromstring(xhtml);     var select = xpath.usenamespaces({"x": "http://www.w3.org/1999/xhtml"});         var nodes = select("//x:*[@id=\"body_column_left\"]/div[4]/table/tbody/tr/[not(contains(./td[2], 'tba'))]", doc);     console.log(nodes);     }); 

any appreciated!

i ended solving issue using cheerioinstead of xpath:

see below:

    var $ = cheerio.load(html);     $('.s_grad br').replacewith("\n");     $('.s_grad thead').remove();     $('.s_grad tr').each(function(i, elem) {         rows[i] = $(this).text();         rows[i] = rows[i].replace(/^\s*[\r\n]/gm, ""); // remove empty newlines         matches.push(new match($(this).find('a').attr('href').substring(7).slice(0, -1))) // create matches     }); 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -