如何将 HtmlAttribute 转换为字符串?

How can I convert an HtmlAttribute to a string?

var web = new HtmlWeb();
var doc = web.Load(page);

var Articles = doc.DocumentNode.SelectNodes("//*[@class = 'b-product-grid-tile js-tile-container']"); 
var href = doc.DocumentNode.SelectNodes("//a[@href]");

foreach (HtmlNode link in href)
            {
                HtmlAttribute att = link.Attributes["href"];
                _entries.Add(new EntryModel { Link = att });

                // att.ToString(); <----- Want to convert the HtmlAttribute to a string.
            }

我的爬虫的完整代码:

入门模型列表:

主要Window:

我需要的链接:

最简单的方法是使用 System.Web.Mvc.TagBuilder class:

var attributes = new { @class = "myClass", id = "elId" };

var tag = new TagBuilder("href");
tag.MergeAttributes(new RouteValueDictionary(attributes));

return tag.ToString();