So now let's try and use our new selector or new each loop we built inside of Chrome console to test
it out.
And let's see how it looks like inside of NodeJS.
So I'm just going to go and hit and paste it inside of NodeJS like this.
And let's take a look at how the console log looks like when we run it.
And we can see that all of the job URLs is being displayed just fine.
Now, maybe you noticed in earlier that if we did a dot text on the A elements, we also display all
the titles because all of the titles is actually A elements also.
This means that we could perhaps tidy up our code inside of NodeJS a little bit, because right now
we have two different groups and it kind of gets a little annoying sometimes.
If you have two different groups and have to merge your elements together with the data properties.
So what we can do instead is just have this loop or this loop for the A element instead, and just get
the titles inside here as well.
So that looks something like this.
We are going to have a curly brace here because we're going to have several statements inside of this,
uh, each loop.
So here we have the title.
And then let's also get the I'm sorry.
Here we have the URL.
And then let's also get the title.
So I'm just going to paste it console statement down here.
And let's delete this each do we have here.
So it now looks something like this.
Let's test it out again and see how it looks like.
And we can see it prints out just fine the title first of the element and then afterwards the URL,
just like we wanted.
Actually it prints the the URL first and then the title, but well that's the devil in the details right?
So now let's put this data into an object instead of just outputting it on our console log.
Dot text for the title and URL.
And there we have the URL.
And then let's just make a object down here.
Actually, we can say return.
Title and URL.
So we return an object from this each loop, and then we make it into a dot map instead.
So returns an array of objects instead.
So we change this dot each to a dot map.
And let's call it jobs over here.
And then let's see what we get if we do a console or log of jobs.
So you can see here the output in my terminal looks kind of weird.
It doesn't just list the title and the URLs, and that is because the dot map inside of cheerio, uh,
outputs an array of jQuery elements or cheerio elements.
It doesn't actually output the object return here, but it's quite easy to get it.
To do that, you just say dot get after this map loop here.
So now if I do that and we do a console log, or if we run the code, we can see we now get all of the
titles and the URLs just fine.
So this is, uh, pretty cool.
By now.
We got all the job URLs and the job titles, but what about all the other sites we have on this site?
We only get for the first page right now, but we also want to get for all the other pages on Craigslist.
So that's what we're going to take a look at.
In the next section we're going to show you I'm going to show you how we can scrape all of the pages
to get all of the jobs and the titles and so forth.