Taken from wikpedia

Taken from wikpedia

Taken from wikpedia

Parse <img src> tag under div in to body in HTML using Swift with the help of SwiftSoup

324 Views Asked by At
    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="utf-8">
        <title></title>
    </head>
    <body>
    <div>
      <p>Taken from wikpedia</p>
      <img src="data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAAUA
        AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO
            9TXL0Y4OHwAAAABJRU5ErkJggg==" alt="Red dot" />
    </div>
    </body>

</html>

I am trying to parse html using SwiftSoup library in Swift . But couldnot find solution to parse under in . I am providing my source code for considertation.

 let pathToInvoiceHTMLTemplate = Bundle.main.path(forResource: "test", ofType: "html")
        do {
            let strHTMLContent = try String(contentsOfFile: pathToInvoiceHTMLTemplate!)
            //print(strHTMLContent)
            let doc: Document = try SwiftSoup.parse(strHTMLContent)
             let body = doc.body()
           
            let title: String = try body!.text();
            print(title)
        
           
        }catch let err{
            print(err)
        }

Please help me by providing the solution. Thanks

0

There are 0 best solutions below