Flutter: Fetch certain elements of a HTML TAG

I have a WordPress API that has a description and its HTML format. there are lots of different types of data like text image link H Tag and so on and also have a video URL. Now How I can get only the video portion from the description.

"content": {
"rendered": "\n<figure class=\"wp-block-video\"><video controls src=\"https://dev.6amtech.com/news/wp-content/uploads/2021/07/Forest-video-article.mp4\"></video></figure>\n\n\n\n<p>Its Just Test Video Article</p>\n",
"protected": false
}

1 answer

  • answered 2021-07-31 07:16 Pablo

    If the output is consistent then you can you extract the URL with simple string manipulation logic. Although some times you can't avoid using RegEx I prefer using something like this to extract the URL if this part of the HTML is going to be consistent.

    String html = "\n<figure class=\"wp-block-video\"><video controls src=\"https://dev.6amtech.com/news/wp-content/uploads/2021/07/Forest-video-article.mp4\"></video></figure>\n\n\n\n<p>Its Just Test Video Article</p>\n";
    String urlPrefix = '<video controls src="';
      
    int urlStart = html.indexOf(urlPrefix) + urlPrefix.length;
    int urlEnd   = html.indexOf('"', urlStart);  
      
    print(html.substring(urlStart, urlEnd));
    // https://dev.6amtech.com/news/wp-content/uploads/2021/07/Forest-video-article.mp4
    

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum