我有这样的HTML:
<table class="down_url_table_td_table">
<tbody><tr>
<td align="center">
<a href="http://dl121.dix3.com/downfile/nash20160419003/a5dd2131/a7b40b3e?md5=6825a9a1c6c564362e9de51a6efb2249" onclick="setCookie('vid1', 'e4d524c17d912066', 1*60*60*1000);">
Click here to download</a>
</td>
</tr>
</tbody></table>
我如何将其转换为Regex?
Regex.IsMatch(input, @"Here"
答案 0 :(得分:2)
我认为做你尝试做的最好方法是使用HtmlAgilityPack
使用该nuget包,您可以使用以下代码:
var html = new HtmlDocument();
html.LoadHtml(@"<table class=""down_url_table_td_table"" >
<tbody>
<tr>
<td align = ""center"" >
<a href = ""http://dl121.dix3.com/downfile/nash20160419003/a5dd2131/a7b40b3e?md5=6825a9a1c6c564362e9de51a6efb2249"" onclick = ""setCookie('vid1', 'e4d524c17d912066', 1*60*60*1000);"">
Click here to download </a>
</td>
</tr >
</tbody ></table >");
var root = html.DocumentNode;
var table = root.Descendants().Where(p => p.GetAttributeValue("class", "").Equals("down_url_table_td_table")).Single();
var href = table.Descendants("a").SingleOrDefault()?.GetAttributeValue("href", "");
答案 1 :(得分:0)