How to get Title and image from Twitter URLs ?
rahulvyas opened this issue · 1 comments
rahulvyas commented
Higher08 commented
Twitter don't get page content immediately, it getting it by JS
You can use hidden webview, improve WKNavigationDelegate, load there twitter URL.
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
webView.evaluateJavaScript("document.getElementsByTagName('html')[0].innerHTML") { (html, error) in
do {
try self.getURL(html)
} catch {
print(error)
}
}
}
Of course no one can guarantee that page loaded, so I advice add delay
getURL
- function with parameter HTML
It look like this
func getURL(_ innerHTML: Any?) throws {
guard let htmlString = innerHTML as? String else {
return
}
let doc = try SwiftSoup.parse(htmlString)
// parsing like usual html
}
Facebook uses Twitter API, not paring