16,555
社区成员
发帖
与我相关
我的任务
分享
For Each child As HtmlNode In node.ChildNodes
If child.Attributes("class") Is Nothing OrElse child.Attributes("class").Value <> "post_item" Then
Continue For
End If
Dim hn As HtmlNode = HtmlNode.CreateNode(child.OuterHtml)
'''如果用child.SelectSingleNode("//*[@class=\"titlelnk\"]").InnerText这样的方式查询,是永远以整个document为基准来查询,
'''这点就不好,理应以当前child节点的html为基准才对。
using System;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
WebBrowser html;
private void Form1_Load(object sender, EventArgs e)
{
html = new WebBrowser();
html.DocumentText = "<html><head></head><body><div id=\"abc\">def</div></body></html>";
html.DocumentCompleted +=new WebBrowserDocumentCompletedEventHandler(html_DocumentCompleted);
}
private void html_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
MessageBox.Show(html.Document.GetElementById("abc").InnerHtml);
}
}
}