Rooney
Rooney

Reputation: 847

How to read the specific video tags from a webpage in c# HtmlagilityPack

I need to read the source src="/~/media/7ca037b0700844cd92db1fe753a4abfc.ashx" inside the video tag file using Htmlagilitypack. How to read it using Htmlagilitypack.

  <video src="/~/media/7ca037b0700844cd92db1fe753a4abfc.ashx" id="video-e054fd59c68443fa928282dc407ff186" class="mediaelement">
          <source type="video/mp4" src="/~/media/7ca037b0700844cd92db1fe753a4abfc.ashx" title="720p HD">
          <source type="video/webm" src="/~/media/5ab38b9c889d43e4a287f6b83c988133.ashx" title="720p HD">
    </video>

Here is my code

HtmlAgilityPack.HtmlDocument document = htmlWeb.Load("http://www.volvocars.com/us/cars/new-models/xc60");
                HtmlNode someNode = document.GetElementbyId("video");

                if (someNode != null)
                {
                    IEnumerable<HtmlNode> allLinks = someNode.Descendants("a");

                    foreach (HtmlNode link in allLinks)
                    {
                        if (link.Attributes.Contains("src"))
                        {
                            if (link.Attributes["src"].Value.StartsWith("source"))
                                Console.WriteLine(link.Attributes["src"].Value);
                        }
                    }
                }

Upvotes: 1

Views: 688

Answers (1)

Dirk Horsten
Dirk Horsten

Reputation: 3845

Use GetElementsByTagName instead of GetElementById

Upvotes: 1

Related Questions