Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何获取AngleSharp项目对象中链接的标题?_C#_Asp.net_Parsing_Anglesharp - Fatal编程技术网

C# 如何获取AngleSharp项目对象中链接的标题?

C# 如何获取AngleSharp项目对象中链接的标题?,c#,asp.net,parsing,anglesharp,C#,Asp.net,Parsing,Anglesharp,以下是一个链接: <a title = "mylink" href="mysite">content</a> 但我需要得到链接的标题和href。如何做到这一点?请注意,AngleSharp使用W3C定义的标准DOM-因此,您只需搜索“如何从DOM中的锚元素获取href”即可检索答案。为了完整起见,示例搜索查询将导致(首次点击谷歌),它回答了您的问题 刚刚翻译成C#意思是 var anchor = item as IHtmlAnchorElement; // Assump

以下是一个链接:

<a title = "mylink" href="mysite">content</a>

但我需要得到链接的标题和href。如何做到这一点?

请注意,AngleSharp使用W3C定义的标准DOM-因此,您只需搜索“如何从DOM中的锚元素获取href”即可检索答案。为了完整起见,示例搜索查询将导致(首次点击谷歌),它回答了您的问题

刚刚翻译成C#意思是

var anchor = item as IHtmlAnchorElement; // Assumption: You have obtained it "only" as an IHtmlElement
string title = item.Title;
string href = item.Href;
备注:
.GetAttribute(“href”)
.href
之间存在差异。前者始终可用(即使在非IHTMlanchoreElement上也是如此),并为您提供实际值。后者是在某些元素(例如,
ihtmlanchorement
)上可用的一个特殊计算版本,它将为您提供一个规范化版本,已经考虑到当前文档的基本URL

TL;DR:
.Href
将为您提供一个绝对URL,而
.GetAttribute(“Href”)
可能为您提供一个相对URL


请注意,AngleSharp使用W3C定义的标准DOM,因此您只需搜索“how to get href from anchor element in DOM”即可检索答案。为了完整起见,示例搜索查询将导致(首次点击谷歌),它回答了您的问题

刚刚翻译成C#意思是

var anchor = item as IHtmlAnchorElement; // Assumption: You have obtained it "only" as an IHtmlElement
string title = item.Title;
string href = item.Href;
备注:
.GetAttribute(“href”)
.href
之间存在差异。前者始终可用(即使在非IHTMlanchoreElement上也是如此),并为您提供实际值。后者是在某些元素(例如,
ihtmlanchorement
)上可用的一个特殊计算版本,它将为您提供一个规范化版本,已经考虑到当前文档的基本URL

TL;DR:
.Href
将为您提供一个绝对URL,而
.GetAttribute(“Href”)
可能为您提供一个相对URL