【发布时间】:2018-11-05 21:57:57
【问题描述】:
我使用 c# 和 AngleSharp 库从 <a> 读取 URL
我可以使用轻松阅读内容
var items = document.QuerySelectorAll("a");
但是我该怎么办,从所有<a> 标签中的href 属性读取URL?
【问题讨论】:
标签: c# .net anglesharp
我使用 c# 和 AngleSharp 库从 <a> 读取 URL
我可以使用轻松阅读内容
var items = document.QuerySelectorAll("a");
但是我该怎么办,从所有<a> 标签中的href 属性读取URL?
【问题讨论】:
标签: c# .net anglesharp
试试这个:
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
【讨论】: