Home  >  Article  >  Backend Development  >  Detailed explanation of how to delete text in specified tags in UL and LI in C#

Detailed explanation of how to delete text in specified tags in UL and LI in C#

黄舟
黄舟Original
2017-06-04 09:43:061859browse

This article mainly introduces the method of C# to delete the text in the specified tag in UL LI, which involves C# regular matching and replacement of the page HTML element For related operating skills, friends in need can refer to

This article describes the method of deleting text in the specified tag in C# in C#. I share it with you for your reference. The details are as follows:

Now the demand is getting more and more abnormal, but we can only try to satisfy it when we make code. Here we first deduct the hyperlink in ul and li. Text

PromptHtml = GetData.GetHTTPInfo(Config.Prompt_Url, "utf-8");
PromptHtml = PromptHtml.Replace("<ul><li>", "");
PromptHtml=PromptHtml.Replace("</li></ul>", "");
string ss = @"<a[\s\S]*?href=""([^" rel="external nofollow" "]*?)""[^>]*?>([\s\S]*?)</a>"; //这里
MatchCollection mcTable = Regex.Matches(PromptHtml, ss);
foreach (Match mTable in mcTable)
{
  if (mTable.Success)
  {
    PromptHtml = mTable.Groups[2].Value;
  }
}
resultHtml = PromptHtml;

The specific data source is as follows:

The code is as follows:

<ul><li><a href="http://localhost/tg.aspx?ID=4194" rel="external nofollow" >哪些主题基金有望爆发?</a></li></ul>

This article deducts the text in span in ul and li:

middlebannerHtml = GetData.GetHTTPInfo(Config.Middlebanner_Url, "utf-8");
middlebannerHtml = middlebannerHtml.Replace("<ul><li>", "");
middlebannerHtml = middlebannerHtml.Replace("</li></ul>", "");
string ss = @"<span>([^<]+)</span>"; //这里
MatchCollection mcTable = Regex.Matches(middlebannerHtml, ss);
foreach (Match mTable in mcTable)
{
  if (mTable.Success)
  {
    middlebannerHtml = mTable.Groups[1].Value;
  }
}
middleContent = middlebannerHtml;

The specific data source is as follows:

The code is as follows:

<ul><li><span>3年5倍涨幅的 不只是股票哦~</span> <a href="http://localhost/tg.aspx?ID=4195" rel="external nofollow" >立即查看</a></li></ul>


The above is the detailed content of Detailed explanation of how to delete text in specified tags in UL and LI in C#. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn