title: Grab Web Content in Swift
body: <p>I have created this task to grab some content from the web:</p>
  
  <pre><code>let task = NSURLSession.sharedSession().dataTaskWithURL(url!, completionHandler: { (data, response, error) -&gt; Void in
  
              if error == nil {
  
                  var urlContent = NSString(data: data, encoding: NSUTF8StringEncoding) as NSString!
  
                  // Get the part that you are interested in from the web page
  
                  var urlContentArray = urlContent.componentsSeparatedByString("&lt;div class=\"entry-summary\" itemprop=\"text\"&gt;")
  
                  // Check if the array contains a value before you print
  
                  if urlContentArray.count &gt; 0 {
  
                      var newsArray = urlContentArray[1].componentsSeparatedByString("&lt;/div&gt;")
  
                      var news = newsArray[0] as String
  
                      self.webView.loadHTMLString(news, baseURL: nil)
  
                      self.webContentLabel.text = news
  
                  }
  
              } else {
  
                  println("Error")
  
              }
  
          })
  </code></pre>
  
  <p>My problem is that the website is formated so that there is a lot of space between the string I'm grabbing first and the <code>&lt;p&gt;</code> that contains the text I'm interested in, hence I get the <code>&lt;p&gt;</code> in the beginning of the grabbed text. If I add the <code>&lt;p&gt;</code> at the end of the string I'm grabbing I get an error saying that the array is empty. I think that the reason for this is the space between "<code>...itemprop="text"&gt;</code>" and "<code>&lt;p&gt;</code>" in the actual html file?</p>
  
  <p>Any ideas?</p>