使用 AngleSharp 库从 href 获取 url

Get url from href using AngleSharp library

我正在使用带有 AngleSharp 库的 c# 从 <a> 中读取 URL 我可以使用

轻松阅读内容
var items = document.QuerySelectorAll("a");

但是我该怎么办,从所有 <a> 标签的 href 属性中读取 URL?

试试这个:

var anchors = document.QuerySelectorAll("a").OfType<IHtmlAnchorElement>();
foreach (var a in anchors)
{
    Console.WriteLine(a.Text); // prints the link inner text
    Console.WriteLine("Href = " + GetAttribute("href")); // prints all the links
}
// if you are using winforms then replace console.writeline with string text