So in the previous sections, you now learned how to use chrome developer tools.
And you learned how to select an element, an element and how to also scrape it from inside NodeJS.
Now we're going to move on to the next lesson lesson inside this site here, and we're going to learn
how to select multiple elements.
So if I go here and inspect these elements we have here.
We can see that they are all h two elements.
So how do we select these elements and how do we get our or how do we get a list of these elements?
So go inside the console and make sure that you have jQuery injected.
So click on this one to inject the jQuery and then let's try and just select the H2 elements.
And there we go.
Now we have this list.
We get get back.
And each of these is a a the HTML element of this these elements we have here.
So if I also go and say dot text, here we go.
Just going to get the text of all the elements in one string.
We can also go and try and print for each of these elements a new line.
So we can say h two dot each.
And then the first parameter is an index and the second one is the element.
And then we can well, I won't go and make an arrow function.
So we have the index and the element here and then make an arrow function.
And then put in a curly brace and then you can press shift and enter to make a new line.
Makes things a little easier to see.
And we can say console log.
And we can say.
The the dollar sign element.
Dot text.
And that's going to print out the text of each element on a new line and then end with a curly brace
and a round parenthesis.
So now it is printing each of these elements text inside the console.
So that means that then you can save each of these elements into a new object inside a MongoDB database
or a new line inside a CSV file, for example.
And again, just like before, we can do the same thing inside of NodeJS.
So if I go ahead and copy this URL with the lesson two dot HTML instead paste it in here.
And then we can simply delete this line where we create a text.
Let's delete that.
So we just have the jQuery or the dollar sign we create here from Cheerio where we load the HTML in.
Let's just select all the H2 elements again and we can do a dot each just like we did inside of the
chrome console.
So we can do another parenthesis here, say index element to a error function.
Then have the curly braces and then we can do exactly the same thing again.
We can say console.log.
Dollar sign element dot text.
And now if we run this inside of Node JS, we should see the same output in the console.
And there we go.
We see the same output again.
And of course, since I am super lazy, I usually just select the code I was fiddling with inside of
Chrome developer tools and I just copy that and paste it inside here.
So you can just copy that and paste it inside here.
And that's it.
That's how you transfer the code that you arrived to inside of Chrome developer tools into NodeJS.
And you also saw how to how you select multiple elements.
Actually, as long as you the elements have the same tag or attribute that you're trying to target,
in this case, it's H2 it jQuery is automatically going to make a list of these elements for us.
So that's how we select multiple elements and that is how we loop through each of these elements and
output their text.