R – The regular expression for finding the image url in tag in HTML using VB .Net code

regex

I want to extract the image url from any website. I am reading the source info through webRequest. I want a regular expression which will fetch the Image url from this content i.e the Src value in the <img> tag.

Best Solution

I'd recommend using an HTML parser to read the html and pull the image tags out of it, as regexes don't mesh well with data structures like xml and html.

In C#: (from this SO question)

    var web = new HtmlWeb();
    var doc = web.Load("http://www.stackoverflow.com");

    var nodes = doc.DocumentNode.SelectNodes("//img[@src]");

    foreach (var node in nodes)
    {
            Console.WriteLine(node.src);
    }