2016-02-29 37 views

回答

1

這裏是一個註釋樣本,讓你開始:

 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 

確保您瞭解XPath的。

+0

我會感謝你 –