Saturday 3 June 2017

Can I use Cheerio to get specific items from a DOM scrape?

I'm trying to get information off a web page, and a lot of the stuff I need uses the same class. Right now I'm using .each but I want to be able to get the specific classes. Basically I want to be able to say class.whatever(1) to get the first result, class.whatever(2) to get the first result, etc.

Here's what I have at the moment:

if (command === "drug") {
message.delete();
let drug = message.content.split(" ")[1];
if (!drug) {
message.reply('Please specify a drug to search for.');
return;
}
let url = `https://psychonautwiki.org/w/index.php?title=${drug}`;
request(url, function(err, res, html){
var $ = cheerio.load(html);
var info = $('.ROATable.mw-collapsible tr');
var infoText = info.text();
})
 }

I'm getting the return I want but everything is in one string. I'd like to get all of the items separately and put them in an array.



via John Doe

No comments:

Post a Comment