title: Get Website Data Using Swift
body: <p>I am trying to use a <code>NSURLSession</code> to pull some data from espn, but I can't seem to get it to work. It prints only <code>nil</code>.</p>
  
  <p>I've tested this method with another page on their website and it worked, but I can't get it to work with the one in the code. Here is the code in question:</p>
  
  <pre><code>var url = NSURL(string: "http://espn.go.com/golf/leaderboard?tournamentId=2271")
  
  if url != nil {
  
      let task = NSURLSession.sharedSession().dataTaskWithURL(url!, completionHandler: { (data, response, error) -&gt; Void in
  
          print(data)
  
          if error == nil {
  
              var urlContent = NSString(data: data, encoding: NSUTF8StringEncoding) as NSString!
  
              print(urlContent)
  </code></pre>
  
  <p>I've also tried changing the encoding type which didn't work either. The data it's printing looks like it's UTF 8 format, so I didn't think that would work but felt I should try.</p>
  
  <p>I feel like I've run out of ideas to work.</p>
  
  <p><strong>Edit :</strong> Should have specified more, <code>print(data)</code> prints out what I expected, encoded data, but <code>print(urlContent)</code> prints <code>nil</code>.</p>