问题描述
我一直试图解析下一页。 'https://marumaru.sale/bbs/cmoic/19997' 并获取这些列表...
' <td class="list-subject">
<a href="/bbs/cmoic/19997/137207">'
//The list should have...
/bbs/cmoic/19997/137207
/bbs/cmoic/19997/137206
/bbs/cmoic/19997/137205
...etc
请问有人可以帮助我使用HtmlAgilityPack吗?
解决方法
private List<string> ExtractAllAHrefTags(HtmlAgilityPack.HtmlDocument htmlSnippet)
{
List<string> hrefTags = new List<string>();
foreach (HtmlNode link in htmlSnippet.DocumentNode.SelectNodes("//a[@href]"))
{
HtmlAttribute att = link.Attributes["href"];
hrefTags.Add(att.Value);
}
return hrefTags;
}
foreach (var item in hrefTags)
{
if(item.IndexOf(@"/bbs/cmoic/")>-1)
{
if (!epilist1.Contains(item))
{
epilist1.Add(site1 + item);
}
}
}
有效。