Example 2 – extracting dealer locations

In this example, we will be extracting content from http://godfreysfeed.com/dealersandlocations.php. This website contains dealer locations information, which is shown in the screenshot that follows:

import reimport requestsdef read_url(url):'''Handles URL Request and ResponseLoads the URL provided using requests and returns the text of page source'''    pageSource = requests.get(url).text    return pageSourceif __name__ == "__main__":

For this and the other examples in this section, we will be using the re and requests libraries in order to retrieve the page source, that is, pageSource. Here, we will be using the read_url() function to do so.

The page contains HTML <form> elements so that we can search for ...

Get Hands-On Web Scraping with Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.