I have a nodejs app, which uses cheerio for extracting parts of html from pages of multiple sites. The app runs through a JSON file and performs the scraping and extraction for each site, for all the URLS, and all cheerio.js queries for each URL:
"site1":{
"urls":{
"http://site1.com/pageA",
"http://site1.com/pageB",
},
"queries":{
"h1": "$('h1').text()"
"numbersFromH1": "$('h1').text().match(/\\d+/)[0]"
}
}
Loading the selectors, e.g. 'h1' using a variable and having a .text() method inside the app would be a no-brainer. However, sometimes I need to .match() or .filter() etc., sometimes chain the methods.
So, is there a way I could load the whole query (selector+methods) and have cheerio execute it?