gpt4 book ai didi

asp.net - 从html anchor 标记获取href值C#

转载 作者:行者123 更新时间:2023-12-02 21:19:31 26 4
gpt4 key购买 nike

如何使用C#仅从html anchor 标记获取href值谢谢你

string ref="<a href="http://www.google.com"></a>";
//i want get result from
//string ref like
//http://www.google.com

最佳答案

您可以使用 HTML 解析库,例如 Html Agility Pack 。例如:

using System;
using HtmlAgilityPack;

class Program
{
static void Main()
{
var doc = new HtmlDocument();
doc.LoadHtml("<a href=\"http://www.google.com\"></a>");
var nodes = doc.DocumentNode.SelectNodes("a[@href]");
foreach (var node in nodes)
{
Console.WriteLine(node.Attributes["href"].Value);
}
}
}

关于asp.net - 从html anchor 标记获取href值C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12087367/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com