Download a webpage


I want to download the source (HTML) of a specific web page, given its complete URL.


// Set the page URL we want to download
let URL = NSURL(string: "")

// Try downloading it
do {
    let htmlSource = try String(contentsOfURL: URL!, encoding: NSUTF8StringEncoding)
catch let error as NSError {
    print("Ooops! Something went wrong: \(error)")


Find answers here

Hi there! Ask Us a Question We are ready to help