<a onclick="" id="ContentPlaceHolder1_rpt_list_LinkButton2_0" class="btn btn-danger btn-xs delete ROLE_Button_SaveSysConfig" href="" style="display: inline-block;">保存</a>
<input type="text" onclick="" id="ContentPlaceHolder1_rpt_list_LinkButton2_0" class="btn btn-danger btn-xs delete ROLE_Button_SaveSysConfig" href="" style="display: inline-block;" />
根据class包含 “ROLE_Button_SaveSysConfig” 匹配出上面的元素,不一定是a标签不一定是input,有可能是div,li span 等等,只要class包含了 就匹配出来这个闭合元素
换HtmlAgilityPack 解决了
换个方式:HtmlAgilityPack + Linq 简洁方便。
嗯 用HtmlAgilityPack 解决了
可以使用 AngleSharp ,示例代码如下:
class Program
{
static async Task Main(string[] args)
{
var html = @"<a onclick="""" id=""ContentPlaceHolder1_rpt_list_LinkButton2_0"" class=""btn btn-danger btn-xs delete ROLE_Button_SaveSysConfig"" href="""" style=""display: inline-block;"">保存</a>
<input type=""text"" onclick="""" id=""ContentPlaceHolder1_rpt_list_LinkButton2_0"" class=""btn btn-danger btn-xs delete ROLE_Button_SaveSysConfig"" href="""" style=""display: inline-block;"" />";
var context = BrowsingContext.New(Configuration.Default);
var document = await context.OpenAsync(req => req.Content(html));
var elements = document.QuerySelectorAll(".ROLE_Button_SaveSysConfig");
foreach(var element in elements)
{
Console.WriteLine(element.Id);
}
}
}
换HtmlAgilityPack 解决了