HtmlAgilityPack 分析Html代码

来源:互联网 发布:snmpwalk windows 编辑:程序博客网 时间:2024/05/07 05:11

HtmlAgilityPack的最新版本为1.4.0。下载地址:http://htmlagilitypack.codeplex.com/

XPath:http://www.w3school.com.cn/xpath/xpath_syntax.asp


using System;using System.Collections.Generic;using System.Linq;using System.Text;using HtmlAgilityPack;namespace HtmlAgilityPack{    class Program    {        static void Main(string[] args)        {            HtmlWeb htmlWeb = new HtmlWeb();            HtmlDocument htmlDoc = htmlWeb.Load(@"http://www.cnblogs.com/");            HtmlNodeCollection anchors = htmlDoc.DocumentNode.SelectNodes(@"//a[@class='titlelnk']");            foreach (HtmlNode anchor in anchors)                Console.WriteLine(anchor.InnerHtml);        }    }}


原创粉丝点击