I am building iOS app where I insert an input string and search this string using Google , then I get the data string back and use it to search for specific word or series of characters
I use URLSessionDataTask to do this
let baseURL = "https://www.google.com/search?q=~+%22education%22%20-intitle:%22profiles%22%20-inurl:%22dir/+%22+site:ca.linkedin.com/in/+OR+site:ca.linkedin.com/pub/"
if let url = URL(string: baseURL) {
let session = URLSession(configuration: .default)
let task = session.dataTask(with: url) { data, response, error in
if error != nil {
print(error)
return
}
if let safeData = data {
let dataString = String(data: safeData, encoding: .ascii)
let decodedString = dataString?.utf8
print(dataString)
}
}
task.resume()
}
the problem is that the dataString I got back is very strange and I cant deal with it , so how can I get it as normal string so every thing is clear enough ???
if let url = URL(string: baseURL) {
let session = URLSession(configuration: .default)
let task = session.dataTask(with: url) { data, response, error in
if error != nil {
print(error)
return
}
if let safeData = data {
let dataString = String(data: safeData, encoding: .ascii)
let decodedString = dataString?.utf8
print(dataString)
}
}
task.resume()
}