【发布时间】:2019-05-28 06:11:08
【问题描述】:
如何从子节点获取值,例如 href 值,并使用带有父节点类名的 html 敏捷包将它们添加到列表中?
我试过这段代码但失败了
var pagedivs = htmlDocument.DocumentNode.SelectNodes("div").Where(e => e.GetAttributeValue("class", "").Equals("pagination"))
.Where(k => k.Descendants().Any(t => t.Name == "li")).ToList();
网页中的 HTML 代码:
<div class="pagination">
<ul class="pagination-list">
<li class="hidden-phone current"><a title="1" href="" class="pagenav">1</a></li>
<li class="hidden-phone"><a title="2" href="/collections/remarkable-products?page=2" class="pagenav">2</a></li>
<li><a title="Next page" href="/collections/remarkable-products?page=2" class="pagenav"><i class="fa fa-chevron-right"></i></a></li>
</ul>
<input type="hidden" name="limitstart" value="0">
</div>
【问题讨论】:
标签: c# html-agility-pack