Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.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# 从html获取值_C#_Regex - Fatal编程技术网

C# 从html获取值

C# 从html获取值,c#,regex,C#,Regex,可能重复: 我不太擅长正则表达式。 所以我的问题是:我怎样才能得到所有的链接 使用解析HTML文件: 使用DLL后,可以获取值 使用这样的代码: linkNode.Attributes["href"] HtmlAgilityPack.HtmlDocument doc=新的HtmlAgilityPack.HtmlDocument(); doc.LoadHtml(@“); var links=doc.DocumentNode.SelectNodes(“//a[@href]”) .选择(a=>

可能重复:

我不太擅长正则表达式。 所以我的问题是:我怎样才能得到所有的链接


使用解析HTML文件:

使用DLL后,可以获取值 使用这样的代码:

linkNode.Attributes["href"]
HtmlAgilityPack.HtmlDocument doc=新的HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(@“);
var links=doc.DocumentNode.SelectNodes(“//a[@href]”)
.选择(a=>a.Attributes[“href”].Value)
.ToList();

使用HtmlAgilityPack是更好的解决方案:另请参见。。
linkNode.Attributes["href"]
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(@"<td><a href=""link"">");

var links = doc.DocumentNode.SelectNodes("//a[@href]")
            .Select(a => a.Attributes["href"].Value)
            .ToList();