• 用C# 正则 提取HTML标签中的值?


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Text.RegularExpressions;

    namespace ConsoleApplication5
    {
        class Program
        {
            static void Main(string[] args)
            {
                string s = @"<tr><td font=red>2009-1-2</td><td font=red>200</td><td>110</td></tr>

    <tr><td>2009-1-3</td><td>200</td><td>110</td></tr>

    <tr><td font=blue>2009-1-4</td><td>200</td><td>110</td></tr>";

                string st = RegStr(s);
                Console.WriteLine(st);
                Console.ReadLine();

            }

            public static string RegStr(string objStr)
            {
                string returnStr = "";
                MatchCollection ml = Regex.Matches(objStr, "<tr>.*?</tr>");
                foreach (Match m in ml)
                {
                    string str = m.Value.Replace("</td></tr>", ",");
                    str = str.Replace("</td>", "|");
                    str = Regex.Replace(str, "<.*?>", "");
                    returnStr += str;
                }
                return returnStr;
            }
        }
    }

  • 相关阅读:
    Nginx + uWSGI 配置django
    django视图缓存的实现
    scrapy 资料
    scrapy 安装
    程序题做题一般步骤
    检查代码的一般步骤
    Mathematical-Analysis-I-4
    Mathematical-Analysis-I-3
    Mathematical-Analysis-I-1
    Mathematical-Analysis-I-2
  • 原文地址:https://www.cnblogs.com/pan11jing/p/1737415.html
Copyright © 2020-2023  润新知