Android Code Snippet Parse Images from Html String

The snippet below will give you a comma separated list of images when providing an html string

Example:
Log(ParseImages(provide_your_html_string_here))



B4X:
Sub ParseImages(HTML As String) As String
 
    Dim objMatch As Matcher
    Dim arrLinks As String
    arrLinks = ""
    ' Match expression to HTML
   
    objMatch = Regex.Matcher("<img[^>]*src=\""([^\""]*)", HTML)
    ' Loop through matches and add <1> to List
      Do While objMatch.find()
        Dim strMatch As String
       
        strMatch = objMatch.Group(1)
        If strMatch.Contains("http://") Then
            arrLinks = arrLinks & strMatch & ","
        End If
       
  Loop
    ' Pass back results
    Return arrLinks
End Sub

TAGS: Parse HTML, Parse Images
 
Top