【发布时间】:2016-04-21 23:39:40
【问题描述】:
我正在尝试使用 HtmlAgilityPack 从 div 中获取值。
我的htmlcode 是这样的:
我需要在news_content_container div 类中获取值,因为您可以看到图中选择了,所以我使用此代码:
var response1 = await http.GetByteArrayAsync("http://www.nsfund.ir/news?"+link);
String source1 = Encoding.GetEncoding("utf-8").GetString(response1, 0, response1.Length - 1);
source1 = WebUtility.HtmlDecode(source1);
HtmlDocument resultat1 = new HtmlDocument();
resultat1.LoadHtml(source1);
var val = resultat1.DocumentNode.Descendants().Where
(x => (x.Name == "div" && x.Attributes["class"] != null && x.Attributes["class"].Value.Contains("news_content_container"))).ToList().First().InnerText;;
但是结果是空的。
【问题讨论】:
标签: c# html .net html-parsing html-agility-pack