Saturday 29 August 2020

web scraping with cheerio

I am newbie at JS and I am trying to do web scraping using cheerio. What I trying to do is getting an specific classes texts into an array like:​​`["file name 1", "file name 2", "file name 3"]` ​, however what I am getting is:​`"file name 1file name 2file name 3"` ​``` const axios = require("axios"); const cheerio = require("cheerio"); const url = "site"; axios(url) .then((response) => { const html = response.data; const $ = cheerio.load(html); let title = $("div[class='col-md-8 col-xs-3'] >span").text(); let content = $("div[class='col-md-2 col-xs-4'] > span[class='badge badge-primary']").text(); let date = $("div[class='col-md-2 col-xs-5'] > span").text(); console.log(title); console.log(content); console.log(date); }) .catch(console.error); ``` ​stackoverlow link can be found here

Submitted August 29, 2020 at 03:13PM by FurtunB

No comments:

Post a Comment