Reputation: 109
im using htmlagility and trying to get both wanted1
and wanted2
the html code is like this
<div class='class1' id='id1'>
<iframe id="iframe1" src="wanted1"</iframe>
<iframe id="iframe" src="wanted2"</iframe>
</div>
but no luck can someone help me please
Upvotes: 0
Views: 431
Reputation: 2372
Here is a commented sample to get you started:
Dim htmlDoc As New HtmlAgilityPack.HtmlDocument
Dim html As String = <![CDATA[<div class='class1' id='id1'>
<iframe id="iframe1" src="wanted1"</iframe>
<iframe id="iframe" src="wanted2"</iframe>
</div>]]>.Value
'load the html string to the HtmlDocument we defined
htmlDoc.LoadHtml(html)
'using LINQ and some xpath you can target any node you want
' //iframe[@src] xpath passed to the SelectNodes function means select all iframe nodes that has src attribute
Dim srcs = From iframeNode In htmlDoc.DocumentNode.SelectNodes("//iframe[@src]")
Select iframeNode.Attributes("src").Value
'print all the src you got
For Each src In srcs
Console.WriteLine(src)
Next
make sure you learn about XPath.
Upvotes: 1