Skip to content

Instantly share code, notes, and snippets.

@sturdysturge
Created December 19, 2020 03:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sturdysturge/b73277dc9df70082d2802914b021c7f5 to your computer and use it in GitHub Desktop.
Save sturdysturge/b73277dc9df70082d2802914b021c7f5 to your computer and use it in GitHub Desktop.
getHTMLSource
import Foundation
func getHTMLSource() -> String {
//Create the URL
guard let url = URL(string: "https://apple.com") else {
fatalError("Could not create URL")
}
// Try downloading the HTML source
do {
return try String(contentsOf: url, encoding: .utf8)
}
//If there is an error
catch let error {
fatalError("Failed to download HTML due to error: \(error.localizedDescription)")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment