You can see when it's done, we now have hundreds of results, I'll scroll, scroll, scroll, scroll, scroll, scroll. Now, when I run this, it will take a little bit longer. I'll pass in that selector of A rel is no follow. I'll undo back to where we were, and now, we can achieve pagination by typing "paginate" between our query and write. Now, we can find this and get the href off of it. You can see now we only get more which is perfect for us. To get the last child, we'll test out this selectorlast-child. We can see that more is the last one of all of those that we found. We'll create an array and an object that just says "test," and see what each of the results gives us. That means it must be the first result in a set of results. When I run this, you'll see that is not what we wanted. To test out that more link, let's just go ahead and see what we get when we do A rel equals no follow. We'll look for that, because the title class isn't helping and the rest of the table stuff isn't helping either. We have to get creative by finding the rel attribute that equals no follow. Hacker News has some very generic, very little styling. To be able to paginate, you have to find the thing you click on to go to the next page, which happens to be this little more link right here. We'll say "link," and then, "grab the href." When I run this, we'll get the first page of results, 1 through 30, but we want to paginate through these and get every page we can. As we loop through each thing we find, the object we want to create will have the rank which was that rank class, the title which was the third TD, we'll pull off the nth child trick by looking for TD number three and grabbing the A tag out of that. We'll go to Hacker News and we'll look for a thing. We can get the rank, the title, and then, the link for the title. I want to grab the rank, a rank of one on this one, and then the third TD, and then, the A tag and the href from that A tag. It looks like a thing, the class of thing is where each of these loop through. To paginate through Hacker News, we first find the elements we'll be loping through.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |