public static string GetElementByClassName(string htmlConetnt, string label, string className)
{
Regex reg = new Regex(string.Format(@"(?is)<{0} class=""{1}""[^>]*>(?><{0}[^>]*>(?<o>)|</{0}>(?<-o>)|(?:(?!</?{0}\b).)*)*(?(o)(?!))</{0}>", label, className));
Match first = reg.Match(htmlConetnt);
return first.Value;
}
public static string GetElementById(string htmlConetnt, string label, string id)
{
Regex reg = new Regex(string.Format(@"(?is)<{0} id=""{1}""[^>]*>(?><{0}[^>]*>(?<o>)|</{0}>(?<-o>)|(?:(?!</?{0}\b).)*)*(?(o)(?!))</{0}>", label, id));
Match first = reg.Match(htmlConetnt);
return first.Value;
}
public static string GetLabel(string htmlConetnt, string label)
{
Regex reg = new Regex(string.Format(@"(?is)<{0}[^>]*>(?><{0}[^>]*>(?<o>)|</{0}>(?<-o>)|(?:(?!</?{0}\b).)*)*(?(o)(?!))</{0}>", label));
Match first = reg.Match(htmlConetnt);
return first.Value;
}
var res2 = GetElementByClassName(responseString2, "div", "listmain");
Regex reg2 = new Regex(@"<a[^>]*href=([""'])?(?<href>[^'""]+)\1[^>]*>", RegexOptions.Multiline | RegexOptions.IgnoreCase);
Match mc2 = reg2.Match(res2);
if (mc2.Success)
{
string content = mc2.Groups["href"].Value.Trim();
}
共有条评论 网友评论