using HtmlAgilityPack to fetch the iframe source

.net c# html-agility-pack xml xpath

Question

In an HTML document, I'm attempting to collect every iFrame source urls. I attempted to use HTML Agility Pack with xpath, but it doesn't seem that I am receiving a list of sources.

HtmlAgilityPack.HtmlDocument myHtml= new HtmlDocument();
myHtml.LoadHtml(htmlString);

foreach (HtmlNode framesrc) in myHtml.DocumentNode.SelectNodes("//iframe/src"))
{
    srcCollection.add(framesrc);
}

Is my xpath incorrect?

1
3
12/27/2018 5:18:15 AM

Accepted Answer

Actually, the following query is used by this open-source HTML parser:

HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();

HtmlNodeCollection nodes = doc.DocumentNode.SelectNodes("//iframe[@src]");


foreach(var node in nodes){
    HtmlAttribute attr = node.Attributes["src"];
    Console.WriteLine(attr.Value);
}
1
1/15/2013 1:45:27 PM

Popular Answer

ifarme possesses quality@src Your XPath should thus be//iframe/@src It will choose.@src of alliframe .



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow