将 htmlagilitypack 节点转换为 htmlelement .net
我刚刚使用 htmlagilitypack 从 html 文档中将所有链接提取为 htmlnode,但我需要从我的函数中将其返回为 htmlelement
Dim Tags As HtmlNodeCollection = docNode.SelectNodes(strXpath)
Dim ListResult As New List(Of HtmlElement)
For Each Tag As HtmlNode In Tags
ListResult.Add(Tag.Element)
Next
Return Nothing
我该如何执行此操作?
I have just used htmlagilitypack to extract all link as htmlnode from an html document, but i need this returned from my function as htmlelement
Dim Tags As HtmlNodeCollection = docNode.SelectNodes(strXpath)
Dim ListResult As New List(Of HtmlElement)
For Each Tag As HtmlNode In Tags
ListResult.Add(Tag.Element)
Next
Return Nothing
How can i do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我怀疑唯一的方法是创建
HtmlElement
,然后从HtmlNode
复制属性和内部 HTML。这是一个扩展方法;它接受对 System.Windows.Forms.HtmlDocument 实例的引用来创建新的 HtmlElement :
要使用它,您可以像这样:
但请注意,我由于不太熟悉 VB.NET,我先为 C# 创建了代码示例,然后将它们翻译为 VB、NET。
I suspect the only way to do it is to create
HtmlElement
, and then copy attributes and inner HTML fromHtmlNode
.Here is an extension method for this; it accepts a reference to a
System.Windows.Forms.HtmlDocument
instance to create a newHtmlElement
:And to use it you could like this:
But please note, I'm not too familar with VB.NET, I created code examples for C# first and then translated them to VB,NET.