How to Build an Events Database Using the ParseHub API, Python & Flask

You just came up with a brilliant idea and want to grab all of the data in the world, consolidate it in one location and make it actually useful for us internet addicts. You look for hours to find the data you need, but the website you want the information from doesn’t have an API.

For static Web pages, building your own scraper isn’t that hard. However, It can take days to get data that loads dynamically with JavaScript on an interactive website. This includes the websites with the navbar that makes you cringe, the nested dropdowns, the data stuck inside a map, or the government site that’s partying like it’s 1999.

In this tutorial we will show you how to scrape one event website, create an API for it, and build a simple Python and Flask web app on top of the data. We will scrape the data with ParseHub, a new browser-based web scraping tool designed to work on JavaScript intensive sites, that runs in Firefox.

In the first part we will scrape an event listing website Peek.com with ParseHub. In the second part we will create our Python and Flask web app that displays all of the events we gathered from Peek.com.

How to scrape dynamic websites with ParseHub

The next steps will show you how to turn Peek.com into an API using the ParseHub browser extension.

Download the ParseHub browser extension and go to Peek.com

  1. Download the ParseHub browser extension.
  2. Go to - www.peek.com - and start a new project.

web scraping parsehub tutorial

Select all of the cities from the dropdown, and tell ParseHub to show activities for each city

  1. Using the select tool, click on the dropdown “Things to Do This Week in San Francisco”.
  2. Use the click tool, to open the dropdown. Now, use the select tool to click on all of the locations in the opened dropdown.
  3. Use the list tool, to create a new empty empty JSON object or empty Excel row for each selected city. Rename the list “locations”.
  4. Use the extract tool, and rename the extraction “city”. You should see all of the city names extracted into your sample results.
  5. Use the click tool again to tell ParseHub to click on each city separately.

web scraping parsehub tutorial

Click the “see more” button to display all of the activity categories for each city

  1. Let’s go to the page with all of the results for each city. Find the “See More in San Francisco” button. Using the select tool, click on the button.
  2. Now, use the navigate tool, to tell ParseHub to click on the button and navigate to a new page. We need to create a new template, for the new page by entering “results” into the textbox and clicking “Create New Template”.

web scraping parsehub tutorial

Click on the categories on the page and navigate to display all of the activities

  1. Let’s get all of the categories on the new page, so we know which activity is “under $50” or “Fun for Locals”. Click on one of the categories using the select tool, hold the SHIFT key and click on another category.
  2. Use the list tool, and rename it “categories”.
  3. Use the extract tool, and rename the extraction “category”. Watch the category names appear in your sample results.
  4. Let’s click on each category and navigate to our final page that lists all of the activities. Use the navigate tool, type in “activities” and click “Create New Template”.

web scraping parsehub tutorial

Filter for activities that cost less than $100 and extract their price and name

  1. Now, let’s get the price and the name for each activity, but only if the activity is under $100. Click on one of the activity prices, hold the SHIFT key and click on another activity price. Make sure you are selecting the <span>.
  2. Use the list tool, to create empty scopes for each activity in JSON.
  3. Use the conditional tool, and type in $e.text <= 100 into the textbox below.
  4. Use the extract tool, and rename the extraction “price”. Scroll down through your sample results and notice that none of the activities over $100 are present.
  5. Use the relative select tool, to select the name of each activity. Click on the price of one activity, and hover over the name of the same activity. Notice how the name and the location is highlighted. Hold down the Ctrl key (or Cmd key on Mac), press the number 2 key one time and watch how only the name is selected. Now click on the name.

web scraping parsehub tutorial

Download your data in JSON/CSV

After setting up your project, you need to run it and wait for your results to appear. You can then download all of the data in JSON or CSV format.

  1. Click “Get Data”, “Run Once”, “Save” and “Run on Servers”. Wait a few minutes and your data should be available for all of the activities in all of the cities.
  2. Beside the “actions” text, click to download your data in JSON or CSV format.

Find your API key and Project token

To interact with your project through the ParseHub API, and to automatically feed the data you scraped into your mobile or web application, first find your API key and project token.

  1. Find your API key under your account page
  2. Get your project token from the “Settings” tab in your www.peek.com project.  
Angelina Fomina

Comments