C#使用xpath对html数据分析

先引用HtmlAgilityPack.dll,没有的话下载一下

直接上代码

                        var doc = new HtmlDocument();
                        doc.LoadHtml(html);//html字符串
                        //获取标签里的值
                        var nodes = doc.DocumentNode.SelectSingleNode("//div[@class='list-container']").InnerText;
                        //获取一个多个节点,进行遍历
                        var nodes_gjjl = doc_gjjl.DocumentNode.SelectNodes("//div[@class='project-follow']");

                        foreach (var item in nodes_gjjl)
                        {
                            string gjjl_time = item.SelectSingleNode("./table/tbody/tr[1]/td[2]/span").InnerText;
                        }

 

posted @ 2020-07-13 14:46  苦逼的猿人  阅读(827)  评论(0编辑  收藏  举报