htmlagilitypack问题以解析链接列表

问题描述

我一直试图解析下一页。 '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);
                    }
                }
            }

有效。

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...