All right, everyone.
Now that we have described exactly what we want to scrape, we are going to write some actual code now.
So let's go ahead and import request from.
Request.
Promise.
And we will also import.
Cheerio.
So quiet.
Cheerio.
And then let's make a function.
We call it scrape titles for now.
Uh, let's call it titles.
Ranks and ratings.
We scrape lots of things in this one, but I'll show you how we do it.
So first of all, we get the titles right and then I will call the function down here in the script
itself.
So we need to get the result using request.
So we say result, await, request get, and we put in the URL for all of the top 100 pages.
We top 100 movies we have here.
Put it in here and then we have the trivial result, the HTML we can select in.
So that's going to be Cheerio.
Load result.
And remember also to use Await, this is also a async function.
Now let's go inside of our browser, inside of the Chrome browser and fiddle around a bit to find the
Cheerio, uh, the Cheerio elements or jQuery elements we can select.
So we go and select, for example, using the select element inside of Chrome developer tools.
We can select the title here.
We select that one.
We can see that each of the movies is actually inside of a table.
So each of them is just a table row.
And inside here we have a cell which has the name title column or the class title column.
It has an a element and this one has a link to the description page.
We see where we can see more about the movie and also the title inside here.
It also has a title attribute, but actually the title attribute contains just the director and actors.
So we are not going to be using that.
We just get the text representation instead of the A element.
Now let's just go and right click this element, select copy and say copy selector and let's go inside
of our console.
So now, um.
If you go and select all of this, I think that's a pretty long selector and it's also only going to
select the first element, but we want to select all of them and luckily we have jQuery enabled on this
page.
So if we go here and say.
That text where we select all of the title column and the a element which contains the title.
We get all of the titles for the different movies.
And the idea is we are going to get an array instead over here, which each of the movie elements.
So let's go ahead and do that.
So we have a movies array.
I will make here and we put in the let's see, the, the more short selector we have here, which works
fine.
And we see CD title comma A and we go and say map instead.
So we return a, a array.
So index element and we use an arrow function here and we are going to return.
We are going to return the title.
Text like so.
And let's see in the end how our movies look.
That's it.
Now let's run the script.
Node Index JS.
Let's run it.
Okay.
So this is something that I stumbled a bit about because it looks like we're actually getting an array
of, um, cherry objects.
Cherry objects, instead of just getting the title that we want.
And so Cherry has a little strange thing about doing that, which means you can chain the functions
or cherry or events.
Basically, if you want to just the titles, you just type dot get after this one and you will get the
values that you really are looking for.
So let's try it again.
All right.
So now we get all of the titles of the different movies in the order they are ranked.
Okay, So in the next section, let's go and get some more data.