Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get iframe source using HtmlAgilityPack

I am trying to get all iFrame source urls on an html doc. I tried using HtmlAgilityPack with xpath - but I don't seem to be getting 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 wrong?

like image 466
kiki Avatar asked Mar 25 '26 10:03

kiki


1 Answers

ifarme has attribute @src. So your XPath should be //iframe/@src. It will select @src of all iframe.

like image 70
Kirill Polishchuk Avatar answered Mar 28 '26 00:03

Kirill Polishchuk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!