首页 > 代码库 > HTML Agility Pack 搭配 ScrapySharp,彻底解除Html解析的痛苦

HTML Agility Pack 搭配 ScrapySharp,彻底解除Html解析的痛苦

var divs = html.CssSelect("div");  //all div elements
var nodes = html.CssSelect("div.content"); //all div elements with css class ‘content’
var nodes = html.CssSelect("div.widget.monthlist"); //all div elements with the both css class
var nodes = html.CssSelect("#postPaging"); //all HTML elements with the id postPaging
var nodes = html.CssSelect("div#postPaging.testClass"); // all HTML elements with the id postPaging and css class testClass
var nodes = html.CssSelect("div.content > p.para"); //p elements who are direct children of div elements with css class ‘content’
var nodes = html.CssSelect("input[type=text].login"); // textbox with css class login
We can also select ancestors of elements:
var nodes = html.CssSelect("p.para").CssSelectAncestors("div.content > div.widget");

参考资料:

http://www.cnblogs.com/shanyou/archive/2012/05/27/2520603.html

HTML Agility Pack 搭配 ScrapySharp,彻底解除Html解析的痛苦