

Wow it looks like Megadeth, Amon Amarth, Suicidal Tendencies, Metal Church and Havok are all playing the same show in October! Sounds like a pretty sick lineup. Now run the app and look at the list of upcoming metal shows in NYC Let’s use CSS selectors with a regular expression to find all td nodes that have an ID beginning with “Text.” Next we’ll loop over those results and apply the day-of-week regular expression.Įdit the parseHTML method to contain the following example code that will print out the text for all of the shows on the page: Using Kanna, developers can use CSS selectors or Xpath queries to navigate through the HTML in a document. With the two patterns for extracting concert data we’re ready to parse the content. This pattern indicates that the text is referring to a concert. To extract just the text nodes for concerts, we will use a second regular expression to find text that begins with the first three letters of a weekday.

Next, you may notice that every piece of text on the page follows that ID pattern, not just the shows. This is the first pattern we’ll use to grab the HTML elements that contain the show info. In our case we want to grab all of the metal shows included in the markup.Įach show exists in a td tag and has an ID of Text followed by some number.

Every web page is different, and sometimes getting data out of them requires a bit of pattern recognition and ingenuity. Now run the app again to see if the request is sent successfullyīefore writing code to parse the content returned from the GET request, let’s first take a look at the HTML that’s rendered by the browser. Open your ViewController.swift and add the following code to the ViewController class: To do this, we need to send a GET request with Alamofire. With the exception in place we can grab HTML from the page we are trying to scrape. Open ist, add a new Key to the Information Property List called App Transport Security Settings and set the Allow Arbitrary Loads value to YES as seen in this GIF:

To make our app work we will need to add an exception to this policy by editing the ist file. Starting in iOS 9, Apple enabled App Transport Security which by default disallows requests to non-secure websites. In our case we want to make a request to and scrape the HTML content that is returned.īefore making the request we have to configure our app to allow making an HTTP request to a non-secure website, or a website that is not accessible via HTTPS. With the starter project in place we can move on to the next step in building the app, making the HTTP request to acquire the concert data. Scraping data from a web page using Alamofire Press “Command-B.” to verify the project builds with those dependencies referenced.
