【问题标题】:htmlagilitypack question to parse list of linkshtmlagilitypack 问题解析链接列表
【发布时间】:2020-08-29 23:46:30
【问题描述】:

我一直在尝试解析以下页面。 '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 做吗?

【问题讨论】:

    标签: c# html-agility-pack


    【解决方案1】:
           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);
                        }
                    }
                }
    

    成功了。

    【讨论】:

      猜你喜欢
      • 2015-03-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-28
      • 2012-12-21
      • 2012-12-13
      • 1970-01-01
      相关资源
      最近更新 更多