【问题标题】:vb.net get src links insade iframes with htmlagilitypackvb.net 使用 htmlagilitypack 获取 src 链接插入 iframe
【发布时间】:2016-03-01 08:56:34
【问题描述】:

我正在使用 htmlagility 并尝试同时获取 wanted1wanted2 html代码是这样的

<div class='class1' id='id1'>
<iframe id="iframe1" src="wanted1"</iframe>
<iframe id="iframe" src="wanted2"</iframe>
</div>

但是运气不好,有人可以帮我吗

【问题讨论】:

    标签: vb.net iframe html-agility-pack src


    【解决方案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。

    【讨论】:

      猜你喜欢
      • 2013-08-28
      • 1970-01-01
      • 2012-02-24
      • 1970-01-01
      • 1970-01-01
      • 2013-08-17
      • 2017-01-20
      • 1970-01-01
      • 2014-09-25
      相关资源
      最近更新 更多