网页抓取(正则表达式)

引言: 网页 抓取后 需要用正则表达式获取内容

我实验了一个例子 怕忘记 先记在这里 (不是完整的网页抓取的解决方案 大家谅解)

如果想取字符串中的value的值 可以这么做

string S=@"
<input type=hidden name=bs value='C8ADC15E27FB3838EFC92AAA9B9672729DD7F639A7A3750B970FD72BC54BD685A8DF4740022B27EF95A632D5D1CC230DAAB0ED1E7B6FF82AF6EB54CCAB89'>
<input type=hidden name=str3 value='BA24925B461A004EFDE758506E7F551E'>
<input type=hidden name=str4 value='39504033001986423360'>
<input type=hidden name=lm value='20998' > ";
        Regex Re = new Regex(@"value=(.*?)\s", RegexOptions.IgnoreCase);
        MatchCollection Mc = Re.Matches(S);

        if (Mc.Count == 0)
        {
          
            throw new Exception();
        }
        foreach (Match M in Mc)
        {
            string a = M.Groups[1].Value;
          
        }

posted @ 2011-03-02 13:49  郑文亮  阅读(1174)  评论(0编辑  收藏  举报