I want to get a video URL from HTML -:
<div class="_53mw" data-store="{"videoID":"607125377233758","playerFormat":"inline","playerOrigin":"permalink","external_log_id":null,"external_log_type":null,"rootID":607125377233758,"playerSuborigin":"misc","useOzLive":false,"playbackIsLiveStreaming":false,"canUseOffline":null,"playOnClick":true,"videoDebuggerEnabled":false,"videoViewabilityLoggingEnabled":false,"videoViewabilityLoggingPollingRate":-1,"videoScrollUseLowThrottleRate":true,"playInFullScreen":false,"type":"video","src":"*https:\/\/video.fdel10-1.fna.fbcdn.net\/v\/t42.1790-2\/271574467_153621553687266_1119427332980623121_n.mp4?_nc_cat=106&ccb=1-5&_nc_sid=985c63&efg=eyJ2ZW5jb2RlX3RhZyI6InN2ZV9zZCJ9&_nc_ohc=HuufVpgJRnEAX8_AEix&_nc_rml=0&_nc_ht=video.fdel10-1.fna&oh=00_AT8eUqTIMXRHidmafowZmL7-o4k2JG0FqA4QbFKNINiQ8Q&oe=61DD4DFB","width":414,"height":621*,"trackingNodes":"FH-R","downloadResources":null,"subtitlesSrc":null,"spherical":false,"sphericalParams":null,"defaultQuality":null,"availableQualities":null,"playStartSec":null,"playEndSec":null,"playMuted":null,"disableVideoControls":false,"loop":true,"numOfLoops":13,"shouldPlayInline":true,"dashManifest":null,"isAdsPreview":false,"iframeEmbedReferrer":null,"adClientToken":null,"audioOnlyVideoSrc":null,"audioOnlyEnabled":false,"permalinkShareID":null,"feedPosition":null,"chainDepth":null,"videoURL":"https:\/\/www.facebook.com\/100069898026392\/videos\/607125377233758\/","disableLogging":false}" data-sigil="inlineVideo">
i am doing this-:
do {
let doc: Document = try SwiftSoup.parseBodyFragment(html)
let headerTitle = try doc.title()
// my body
let body = doc.body()
// elements to remove, in this case images
let undesiredElements: Elements? = try body?.select("a")
//remove
try! undesiredElements?.remove()
// print("Header title: \(headerTitle)")
print("Header body: \(body)")
}
How to do this with swift soup
Try this code - :
do {
let doc: Document = try SwiftSoup.parse(html)
let size = try doc.getElementsByClass("_53mw").first()
let data = try size?.attr("data-store")
print(data!)
let videoUrl = convertToDictionary(text: data!)
let url = videoUrl!["src"] as! String
print(url)
} catch Exception.Error(let type, let message) {
print("Message: \(message)")
} catch {
print("error")
}