I have a HTML Document which I would like to parse. I am trying to use cheerio to parse the HTML file.
<ul data-reactid=".0.1.0.0.1.1.0.0.0.0.1.0">
<li class="_1ht1 _1ht2" data-reactid=".0.1.0.0.1.1.0.0.0.0.1.0.1:$user=xyz">
.
.
.
.
<span data-reactid=".0.1.0.0.1.1.0.0.0.0.1.0.1:$user=xyz.0.0.$right.0.0.1.$left.0.1:0">
My Random Text
</span>
</li>
</ul>
From my HTML I am am trying to extract the first instance of the ul tag with data-reactid=".0.1.0.0.1.1.0.0.0.0.1.0"
In that the very first li tag, I want to extract the user, in this case xyz. After that I want to find the text within the span class mentioned in the code.
Through Cheerio I tried the following:
var cheerio = require('cheerio'),
fs = require('fs');
fs.readFile('index.html', 'utf8', dataLoaded);
function dataLoaded(err, data) {
$ = cheerio.load(data);
console.log("Trying out " + JSON.stringify($("<ul data-reactid=\".0.1.0.0.1.1.0.0.0.0.1.0\">").data()));
}
It prints Trying out {"reactid":".0.1.0.0.1.1.0.0.0.0.1.0"}
How do I get the value inside the HTML?
Note: xyz is dynamic and it will change
` as output, right?
– Patel Jul 18 '15 at 09:14