- Joined
- 11 yrs. 6 mth. 27 days
- Messages
- 5,381
- Reaction score
- 18,380
- Age
- 45
- Wallet
- 11,590$
- [email protected]
hey guys, this is a followup to my previous post in which we created a class for a webBot object, in this tutorial we're going to use that class to try and get an idea of how we can utilise that code in a practical way. For our example we will be writing a simple subreddit scraper, it will have a default subreddit but will accept an optional parameter to override it with a subreddit of your choice. It then will request the page and scrape all of the post titles and links and print them to the screen. Lets get started!
In this portion of our code we iterate through our two arrays and run each set through return_between() for the $clean_titles array we can use the exact same anchors as above but we have to slightly modify the $clean_links to only use '<link>' as our opening anchor this time. This is because we have already extracted the set we want but we want to keep the URLs in tact, so we have to remove them from the anchor the second time around.
In this portion of our code we iterate through our two arrays and run each set through return_between() for the $clean_titles array we can use the exact same anchors as above but we have to slightly modify the $clean_links to only use '<link>' as our opening anchor this time. This is because we have already extracted the set we want but we want to keep the URLs in tact, so we have to remove them from the anchor the second time around.