I’m using cheerio and axios to do some web scraping. Right now, I’m trying to select $(".color-data")
, which should return three elements. However, it outputs a large, messy object, and if I use .toArray()
, I get an error.
Any ideas on what to do? Here’s my code:
//import our packages
const axios = require("axios")
const cheerio = require("cheerio")
const data = []
//load html-color-names
axios.get("http://www.html-color-names.com/darkorchid.php")
.then(html => {
//console.log(html.data)
const $ = cheerio.load(html.data)
var arr = $(".color-data")
console.log(arr) //returns object, arr.toArray() is a no go, arr.text() returns string
})
Update: I’ve tried https://teamtreehouse.com/community/returning-an-array-from-a-class-in-jquery - they suggest using each and pushing it to an array, but it doesn’t work. Any other ideas?
Update 2: If i use .text()
, I get:
DarkOrchid
#9932cc
rgb(153, 50, 204)
There’s too much whitespace to efficiently split this. I tried .html()
, and I just get
DarkOrchid
.data()
returns an empty object {}
.
More whitespace, again. Any ideas?