So in order to fix this, we have to change our strategy.
Instead of grabbing the points, we should grab what we call the subtext.
And the subtext is, well, what comes underneath the title?
Because every single title has these subtext, and underneath it we have the score.
Now, in our case, the top one over here doesn't actually have the score.
You see here that we have the subtext, but there is no score.
So what we can do is do a little extra check.
If we go back to our code, we can now change this a little bit so that instead of having the votes
here.
What we can do is grab the subtext.
And this is going to be the subtext class that we're going to grab to make sure that all links are going
to have the subtext.
So let's select subtext.
And in here, we're going to change our strategy to say that, hey, the votes that I want or in our
case, the vote, because we're looping through here, is going to equal the subtext.
At the place that we're looping through and we're going to select.
The class.
Of course.
So remember if we scroll down.
Class of score is what we want and that's going to be our vote.
Now, remember, there are some cases where the vote won't be there.
So what we can do now?
Is say, hey, if vote.
Has no length because remember, we're going to get an array.
If this length is zero, that's going to evaluate to false.
But if it's not zero, then I want you to do all of this.
So now our vote.
Instead of doing index here, we can just say vote, get tax and replace the points.
But it's only going to run if the vote list exists.
So let's test this out.
I'm going to run.
Oh, and we have to change our parameters from votes here to subtext.
So let's do that.
Let's say subtext.
Subtext.
If I save and run this again.
We get list object has no attribute get taxed because again we get an array here so we have to grab
the first element in the array, remember, because we're grabbing the subtext.
So if I run this again.
All right.
It looks like we finally have our points and no errors.
That's awesome.
So you see here when your web scraping, you're testing out your assumptions and maybe you make some
mistakes.
So you want to adjust and fix them based on what the website does.
Now in here, the last thing I want to do is to actually add the vote into our Hacker News append here.
So let's remove the print here.
And I'm going to add.
The.
Votes.
As the well, the points that we get here, let's make this a little smaller just so you can see.
Perfect.
So we have this Hacker News append, so let's test it out.
Now, before I show you, I want to show you something.
When it comes to enumerate, why did we use enumerate?
Well, it's because in here we have two lists, the links and the subtext, and we're only enumerating
over the links list.
And subtext, well, is not being enumerated.
So what happens here is we need the index so that we can access this subtext within our loop.
Because otherwise well, if we didn't enumerate, there's no way to grab both links and subtext items.
So for example, in here my links can just be converted to item.
And.
Item, but subtext.
We'll just have to use the index that we have here.
Hopefully that makes sense.
Now let's print this and see what it looks like.
I'm going to print.
Hit safe and let's run our script.
Oh, and we have a little mistake here.
We got to make sure that the curly brackets are outside.
If I run this.
All right.
We see that we get our data and let's just check we have title about security issues on VLC, which
has a vote of 307.
Let's just check that on the page if I scroll down.
About the security issue on VLC, which has 307 votes.
Awesome.
So this seems to be working.
Our script is working.
Wonderful.
Now, the last thing I want to add here is this whole printing is a little ugly and ideally we can print
things nicely to the terminal.
Well, we have a module, a built in module that we can use in Python.
Called pretty print and we can just import it like this p print.
Now check this out.
If instead of print here.
I do p print.
P print.
Let's see if we notice a difference.
All right.
It's a little neater now.
We have a little bit of more spacing and well, it's a lot cleaner than it was before.
That's really nice.
Now, the other thing is, as we mentioned, we only care about the votes that have over 100.
So let's add another if statement here.
Let's make this a little bit bigger.
And within the points here, we'll just say if.
Points.
Ah, higher than 99.
Then we'll append to our updated Hacker News.
Let's save.
Give this a go.
All right.
It looks like we only have stories that have over 100 points, so it's nice and clean.
A lot smaller now.
Awesome.
Now there's a few more things I want to add to this.
Ideally, these votes are ranked, so we have the highest vote at the top and at the bottom, the lowest
vote.
This way, it's easier for me to decide what story I should read first.
Let's explore that in the next video.
Bye bye.