您的位置:首页 > Web前端 > HTML

html解析器 HtmlAgilityPack

2015-09-07 15:42 495 查看
可以到 http://www.oschina.net 开源中国社区下载相关Dll,百度有很多如何使用的资料

HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
            doc.Load("city.html");
            HtmlNodeCollection cityAll = doc.DocumentNode.SelectNodes("//div[starts-with(@class,'tablebox')]//table/tr/td/a[@href]");
            string text = "";
            string wrong = "";
            foreach (HtmlNode link in cityAll)
            {
                if (link.Attributes["onclick"] == null)
                    continue;
                 text += link.Attributes["onclick"].Value;
                 
             }
          
            FileStream fs1 = new FileStream("E:\\HtmlTxt.txt", FileMode.Create, FileAccess.Write);//创建写入文件 
            StreamWriter sw = new StreamWriter(text );
            sw.WriteLine(all);//开始写入值
            sw.Close();
            fs1.Close();



doc.DocumentNode.SelectNodes("……")其中的参数可以去网上搜,有很多介绍如何使用的,可以对Class进行选择,属性进行选择,路径进行选择。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: