I am trying to parse html from a URL:
func fetch(url: URL, completion: @escaping ((Result) -> Void)) {
var request = URLRequest(url: url)
request.httpMethod = "GET"
let session = URLSession.init(configuration: URLSessionConfiguration.default)
session.dataTask(with: request) { [weak self] data, _, error in
guard let self = self else { return }
if let error = error {
completion(.failure(error))
return
}
if let data = data, let html = String(data: data, encoding: .ascii) {
completion(.success(self.metaTagsDictionary(for: html)))
return
} else {
completion(.failure(ParseError.fail))
return
}
}.resume()
}
I then print the result with:
dict.keys.forEach { print(dict[$0]) }
However I seem to be getting a bunch of weird characters in the string e.g:
命,科科都能å•ï¼ä¾†è©¦è©¦ 2020 å¹´å•†å‘¨å ±å°Žçš„æœ€æ–°å®¶æ•™æ¨¡å¼å§ã€‚")
any idea what this is? Am I using the wrong encoding?