【问题标题】:Get url from href using AngleSharp library使用 AngleSharp 库从 href 获取 url
【发布时间】:2018-11-05 21:57:57
【问题描述】:

我使用 c# 和 AngleSharp 库从 <a> 读取 URL 我可以使用轻松阅读内容

var items = document.QuerySelectorAll("a");

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

【问题讨论】:

    标签: c# .net anglesharp


    【解决方案1】:

    试试这个:

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-07-07
      • 2016-07-01
      • 2022-06-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-24
      相关资源
      最近更新 更多