加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

正则匹配百度结果

发布时间:2020-12-14 01:59:32 所属栏目:百科 来源:网络整理
导读:重点是先抓取td里的内容,其它的就好说了: using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.IO;using System.Text.RegularExpressions;namespace ReadFile{ class Program { static void Main(string[] ar

重点是先抓取<td>里的内容,其它的就好说了:

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

namespace ReadFile
{
    class Program
    {
        static void Main(string[] args)
        {
            string FilePath = @"E:vsbd.txt";
            StreamReader sr = new StreamReader(FilePath,Encoding.GetEncoding("UTF-8"));
            string FileContent = sr.ReadToEnd();
            FileContent = Regex.Replace(FileContent,"[rnt]+","");
            string PatternTable = "(?i)<table class="result"[^>]*?>(?:(?!</?table>)[sS])*?</table>";
            string PatternBlock = "<td class="c-default" >(?:(?!</?td>)[sS])*?</td>";
            MatchCollection mc = Regex.Matches(FileContent,PatternBlock,RegexOptions.Multiline);
            Match mm = Regex.Match(FileContent,RegexOptions.Multiline);
            //Debug.WriteLine(mm.Groups.Count);
            foreach (Match mat in mc)
            {
                Console.WriteLine("================================================");
                Console.WriteLine(mat.Value);
            }

            Console.Read();
        }
    }
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读