1
if let myURL = NSURL(string: url) {
    do {
       let myHTMLString = try NSString(contentsOf: myURL as URL, encoding: String.Encoding.utf8.rawValue)
          print("html \(myHTMLString)")
       }
       catch {
          print(error)
       }
}

I am trying to get the HTML code from amazon.com in xcode using the above code, but it keeps giving the following error:

2020-06-26 21:34:27.596936-0700 DocScan[12206:3119560] CFURLCopyResourcePropertyForKey failed because it was passed an URL which has no scheme Error Domain=NSCocoaErrorDomain Code=256 "The file “amazon.com” couldn’t be opened." UserInfo={NSURL=amazon.com} amazon.com

What am I doing wrong and is there any better way to extract HTML code from a website like amazon.com?

0 Answers0