获得HTML锚标记C#href的值 [英] get href value from html anchor tag C#
本文介绍了获得HTML锚标记C#href的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何只从HTML锚标记使用C#获取href值
谢谢
REF字符串=< A HREF =http://www.google.com>< / A>中;
//我想要得到的结果
//字符串REF像
//http://www.google.com
解决方案
如果你想做到这一点没有 HtmlAgilityPack ,然后你可以做到这一点使用的常规防爆pression :
REF串= @< A HREF =http://www.google.com>测试与LT; / A>中;
VAR的regex =新的正则表达式(< A [^>] * HREF =(?:'?。?(小于HREF> *)')|(?:\\?。?(小于HREF> *) \\),RegexOptions.IgnoreCase);
VAR的url = regex.Matches(REF).OfType<比赛方式>()选择(M => m.Groups [HREF]值。).SingleOrDefault();
希望它可以帮助你。
how to get the href value only from html anchor tag using C# thank you
string ref="<a href="http://www.google.com"></a>";
//i want get result from
//string ref like
//http://www.google.com
解决方案
If you want to do this without HtmlAgilityPack then you can do this using regular Expression :
string ref= @"<a href=""http://www.google.com"">test</a>";
var regex = new Regex("<a [^>]*href=(?:'(?<href>.*?)')|(?:\"(?<href>.*?)\")", RegexOptions.IgnoreCase);
var urls = regex.Matches(ref).OfType<Match>().Select(m => m.Groups["href"].Value).SingleOrDefault();
Hope it helps you.
这篇关于获得HTML锚标记C#href的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文