I'm using npmscraper. I have two nearly identical functions below, which i want to basically combine the results they return into one array in key-value pair format.
First function returns ['orange','apple','grape']
Second function returns ['www.orange.com','www.apple.com','www.grape.com']
(very simplified) sample data to scrape from foo.com ###
<p>orange <a href="www.orange.com">click here</a></p>
<p>apple <a href="www.apple.com">click here</a></p>
<p>grape <a href="www.graphe.com">click here</a></p>
// Begin node app
var scraperjs = require('scraperjs');
// first function
scraperjs.StaticScraper.create('https://foo.com/')
.scrape(function($) {
return $(".entry p").map(function() {
return = $(this).text();
}).get();
})
.then(function(fruit) {
// after some cleaning up...
console.log(fruit)
//returns ['orange','apple','grape']
})
-----------------------
// second function gets the links
scraperjs.StaticScraper.create('https://foo.com/')
.scrape(function($) {
return $(".entry a").map(function() {
return = $(this).attr('href');
}).get();
})
.then(function(links) {
console.log(links)
// returns ['www.orange.com','www.apple.com','www.grape.com']
})
(EDITED) What I'd like is something like:
[{fruit: 'orange'; link 'www.orange.com'},{fruit: 'apple'; link 'www.apple.com'}]
What I'd like is something likethis is not a valid javascript construct ... did you mean the[]to be{}...return =??? really? do you claim your code to actually produce the current output?