在vb.net(2010)中从HTML创建DOM [英] create DOM from HTML in vb.net ( 2010 )
本文介绍了在vb.net(2010)中从HTML创建DOM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
想要用HTML格式创建HTML格式的DOM。
我目前有一个能够从网站获取HTML并将其转储到文本框中的程序。从这个我是创建一个DOM。
任何人有任何想法...这看起来很完美....
使用.NET的HTML DOM [ ^ ]
但是,它的C#和不能用VB工作。
谢谢。
Hi All,
Looking to create a DOM in HTML from aload of HTML.
I currently have a program that is capable of getting the HTML from a website and dumping it into a textbox. from this i was to create a DOM.
Anyone have any ideas... this looks perfect....
HTML DOM Using .NET[^]
However, its C# and won''t work in VB.
Thanks.
推荐答案
如果你使用WebBrowser
类 [< a href =http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.aspxtarget =_ blanktitle =New Window> ^ ],然后您可以直接从Document
属性获取DOM,该属性是HtmlDocument
类 [ ^ ]。
If you use theWebBrowser
Class[^], then you can get the DOM direct from theDocument
property, which is an instance of theHtmlDocument
Class[^].
此代码从一个继承自的控件中获取HTML WebBrowser,并使用DOM查找其中的特定表和项。
This code gets the HTML from a control that is inherited from WebBrowser, and uses the DOM to find particular tables and items within it.
// logout from 3Rings
HtmlElement element = Document.GetElementById("directory_list");
// get the table header collection (one element)
HtmlElementCollection trCollection = element.GetElementsByTagName("THEAD");
// get the header items collection
trCollection = trCollection[0].GetElementsByTagName("TH");
int xName = -1;
int xEmail = -1;
int nIndex = 0;
foreach (HtmlElement trItem in trCollection)
{
Debug.WriteLine(trItem.InnerText);
string strHeading = trItem.InnerText.Trim().ToLower();
if (strHeading.Equals("name"))
xName = nIndex;
if (strHeading.Equals("email"))
xEmail = nIndex;
nIndex++;
}
文档将提供更多示例,或者您可以在CodeProject文章中搜索更多样本。
The documentation will offer further examples, or you could search the CodeProject articles for more samples.
这篇关于在vb.net(2010)中从HTML创建DOM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文