Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert cheerio object to string

I am extracting metatags from page:

$ = cheerio.load(html)
metaTags = $('meta')

and it works fine, but I need that metaTags array contain strings - not objects of cherrio, like here:

["<'meta something=1231'><'/meta'>", "<'meta sometag=44242'><'/meta'>"]

p.s. I dont need ' character it just stackoverflow.com missunderstaning

I have made such , method:

toHtml = (el) ->
  return el.html()

but it doesnt work : getting empty results (using map with it)

metaTags.map (i, el) -> console.log i.toHtml(el)

like image 433
Jesus_Maria Avatar asked Dec 24 '22 16:12

Jesus_Maria


1 Answers

let arrayOfHTMLstrings = $('meta').toArray().map( (el, index) => el.toString() );

According to cheerio official doc

like image 147
Dmytro Lisunov Avatar answered Jan 05 '23 04:01

Dmytro Lisunov