将html转化成dom对象 然后进行分析


 

private delegate string DelegateGetDocument();
private string GetDocument()
{
return webCollection.Document.Body.InnerHtml;
}

*****************************************

下面使用的是webbrowser抓取数据

*****************************************

HtmlAgilityPack.HtmlDocument document = new HtmlAgilityPack.HtmlDocument();//using HtmlAgilityPack;
string doc = "";
doc = this.Invoke(new DelegateGetDocument(GetDocument)).ToString();
document.LoadHtml(doc);
HtmlNode root = document.DocumentNode;//root根节点

分析举例:

HtmlNodeCollection TargetNodes = root.SelectNodes("//h3[@class='summary']");//h3 class="summary"

HtmlNode priceLabel = root.SelectSingleNode("//strong[@id='J_StrPrice']");

HtmlNode TargetNode = TargetNodes[ii].SelectSingleNode("./a");

HtmlNode DivNode = root.SelectSingleNode("//div[@id='thread_theme_3']");
HtmlNodeCollection TagretNodes = DivNode.SelectNodes("//@*");//遍历所有标签

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM