Friday 2 June 2017

How can I format a return from an HTML scrape? (Cheerio)

I'm using Cheerio to scrape an html page using the following code:

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}`;
console.log(url);
request(url, function(err, res, html){
var $ = cheerio.load(html);
$('.ROATable.mw-collapsible').each(function(i, element) {
  var node = $(this);
  let drugInfo = node.text();
  message.channel.send(drugInfo);
  return;
})

})
}

I'm getting the return I want but it's full of weird spacing that I want to format to like nice. Would removing all of the spaces be the best first step?

Image of the return



via John Doe

No comments:

Post a Comment