HtmlAgilityPack 分析Html代码

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);
        }
    }
}


猜你喜欢

转载自blog.csdn.net/xiongxyt2/article/details/9764165