</DIV>
</td></tr></table>
<p style="margin-left:15px">
<table border=0><tr><td><font size=-1> 
<a href="http://news.baidu.com/ns?cl=2&rn=20&tn=news&word=title%3A%28%B0%D9%B6%C8%29&web=5" target="_blank"><font color="#c60a00">百度</font>的相关新闻</a> &nbsp;-
<a href="http://news.baidu.com/view.html?from=web" target="_blank"><font color="#8D88F0">今日焦点新闻</font></a>
</font></td></tr><tr><td><font><font size=-1>&nbsp;&nbsp;<a href="http://news.baidu.com/ns[0]_http://www.nbd.com.cn/newShow.asp?D_ID=91186&web=5&query=%B0%D9%B6%C8" target="_blank"><font color=#C60A00>百度</font>VS阿里巴巴=最强VS最大</a> <font class=c>每日经济新闻 4小时58分钟前</font></font><br></font></td></tr></table>
</p>
<table border="0" cellpadding="0" cellspacing="0"><tr><td class=f><a href="http://www.baidu.com/" target="_blank"><font size="3"><font color=#C60A00>百度</font>一下,你就知道</font></a><br><font size=-1>新闻网页贴吧知道MP3图片 帮助 高级 空间 | 更多&gt;&gt; 把<font color=#C60A00>百度</font>设为首页 企业推广 | 搜索风云榜 | 关于<font color=#C60A00>百度</font> | About Baidu 2007 Baidu 使用<font color=#C60A00>百度</font>前必读 京ICP证030173号... <br><font color=#008000>www.baidu.com/  2K 2007-12-20  </font>  <br><a class="m" target="_blank" href="s?lm=0&si=&rn=100&tn=baiduadv&ie=gb2312&ct=0&wd=%B0%D9%B6%C8%20site%3Awww%2Ebaidu%2Ecom+&cl=2">www.baidu.com&nbsp;上的更多结果</a></font></td></tr></table><br><table border="0" cellpadding="0" cellspacing="0"><tr><td class=f><a href="http://site.baidu.com/" target="_blank"><font size="3"><font color=#C60A00>百度</font>网址大全</font></a><br><font size=-1><font color=#C60A00>百度</font> 新浪 搜狐 网易 腾讯QQ 更多&gt;&gt; 新闻 新浪新闻 人民网 新华网 中央电视台 凤凰网 联合早报 更多&gt;&gt; 邮箱 163...<font color=#C60A00>百度</font>视频搜索 更多&gt;&gt; 企业推广 | 搜索风云榜 | 关于<font color=#C60A00>百度</font> | 网友反馈 2007 Baidu 使用<font color=#C60A00>百度</font>前必读 京ICP证030173号... <br><font color=#008000>site.baidu.com/ 25K 2007-12-24  </font>  <br></font></td></tr></table><br><table border="0" cellpadding="0" cellspacing="0"><tr><td class=f><a href="http://mp3.baidu.com/" target="_blank"><-----------------------------------------我通过百度的高级搜索提取到搜索到的html代码,现在要做的是将信息文字如(搜索关键字“百度”就出现
第一条:百度一下,你就知道
新闻网页贴吧知道MP3图片 帮助 高级 空间 | 更多>> 把百度设为首页 企业推广 | 搜索风云榜 | 关于百度 | About Baidu 2007 Baidu 使用百度前必读 京ICP证030173号... 
”第2条:百度网址大全
百度 新浪 搜狐 网易 腾讯QQ 更多>> 新闻 新浪新闻 人民网 新华网 中央电视台 凤凰网 联合早报 更多>> 邮箱 163...百度视频搜索 更多>> 企业推广 | 搜索风云榜 | 关于百度 | 网友反馈 2007 Baidu 使用百度前必读 京ICP证030173号... 
)提取出来,自己对正则表达式不太熟,望大家帮忙,谢谢!

解决方案 »

  1.   


    <textarea id="txt">
    </DIV> 
    </td> </tr> </table> 
    <p   style="margin-left:15px"> 
    <table   border=0> <tr> <td> <font   size=-1>   
    <a   href="http://news.baidu.com/ns?cl=2&rn=20&tn=news&word=title%3A%28%B0%D9%B6%C8%29&web=5"   target="_blank"> <font   color="#c60a00"> 百度 </font> 的相关新闻 </a>   &nbsp;- 
    <a   href="http://news.baidu.com/view.html?from=web"   target="_blank"> <font   color="#8D88F0"> 今日焦点新闻 </font> </a> 
    </font> </td> </tr> <tr> <td> <font> <font   size=-1> &nbsp;&nbsp; <a   href="http://news.baidu.com/ns[0]_http://www.nbd.com.cn/newShow.asp?D_ID=91186&web=5&query=%B0%D9%B6%C8"   target="_blank"> <font   color=#C60A00> 百度 </font> VS阿里巴巴=最强VS最大 </a>   <font   class=c> 每日经济新闻   4小时58分钟前 </font> </font> <br> </font> </td> </tr> </table> 
    </p> 
    <table   border="0"   cellpadding="0"   cellspacing="0"> <tr> <td   class=f> <a   href="http://www.baidu.com/"   target="_blank"> <font   size="3"> <font   color=#C60A00> 百度 </font> 一下,你就知道 </font> </a> <br> <font   size=-1> 新闻网页贴吧知道MP3图片   帮助   高级   空间   |   更多&gt;&gt;   把 <font   color=#C60A00> 百度 </font> 设为首页   企业推广   |   搜索风云榜   |   关于 <font   color=#C60A00> 百度 </font>   |   About   Baidu   2007   Baidu   使用 <font   color=#C60A00> 百度 </font> 前必读   京ICP证030173号...   <br> <font   color=#008000> www.baidu.com/     2K   2007-12-20     </font>     <br> <a   class="m"   target="_blank"   href="s?lm=0&si=&rn=100&tn=baiduadv&ie=gb2312&ct=0&wd=%B0%D9%B6%C8%20site%3Awww%2Ebaidu%2Ecom+&cl=2"> www.baidu.com&nbsp;上的更多结果 </a> </font> </td> </tr> </table> <br> <table   border="0"   cellpadding="0"   cellspacing="0"> <tr> <td   class=f> <a   href="http://site.baidu.com/"   target="_blank"> <font   size="3"> <font   color=#C60A00> 百度 </font> 网址大全 </font> </a> <br> <font   size=-1> <font   color=#C60A00> 百度 </font>   新浪   搜狐   网易   腾讯QQ   更多&gt;&gt;   新闻   新浪新闻   人民网   新华网   中央电视台   凤凰网   联合早报   更多&gt;&gt;   邮箱   163... <font   color=#C60A00> 百度 </font> 视频搜索   更多&gt;&gt;   企业推广   |   搜索风云榜   |   关于 <font   color=#C60A00> 百度 </font>   |   网友反馈   2007   Baidu   使用 <font   color=#C60A00> 百度 </font> 前必读   京ICP证030173号...   <br> <font   color=#008000> site.baidu.com/   25K   2007-12-24     </font>     <br> </font> </td> </tr> </table> <br> <table   border="0"   cellpadding="0"   cellspacing="0"> <tr> <td   class=f> <a   href="http://mp3.baidu.com/"   target="_blank">百度mp3</a>
    </textarea>
    <script>
    var reg=/<\/?\w+[^<>]*>/gi;
    var txt=document.getElementById("txt").value;
    alert(txt);
    alert(txt.replace(reg,""));
    </script>
      

  2.   

    再进一步,超过8000字了,我把原文件去掉一部分~~~<textarea id="txt">
    <table border="0" cellpadding="0" cellspacing="0"><tr><td class=f><a href="http://www.baidu.com/" target="_blank"><font size="3"><font color=#C60A00>百度</font>一下,你就知道</font></a><br><font size=-1>新闻网页贴吧知道MP3图片 帮助 高级 空间 | 更多&gt;&gt; 把<font color=#C60A00>百度</font>设为首页 企业推广 | 搜索风云榜 | 关于<font color=#C60A00>百度</font> | About Baidu 2007 Baidu 使用<font color=#C60A00>百度</font>前必读 京ICP证030173号... <br><font color=#008000>www.baidu.com/  2K 2007-12-20  </font> - <a href="http://cache.baidu.com/c?word=%B0%D9%B6%C8&url=http%3A//www%2Ebaidu%2Ecom/&p=882a960195904eac42f6d12f17&user=baiduadv" target="_blank" class=m>百度快照</a> <br><a class="m" target="_blank" href="s?lm=0&si=&rn=10&tn=baiduadv&ie=gb2312&ct=1&wd=%B0%D9%B6%C8%20site%3Awww%2Ebaidu%2Ecom+&cl=2">www.baidu.com&nbsp;上的更多结果</a></font></td></tr></table><br><table border="0" cellpadding="0" cellspacing="0"><tr><td class=f><a href="http://site.baidu.com/" target="_blank"><font size="3"><font color=#C60A00>百度</font>网址大全</font></a><br><font size=-1><font color=#C60A00>百度</font> 新浪 搜狐 网易 腾讯QQ 更多&gt;&gt; 新闻 新浪新闻 人民网 新华网 中央电视台 凤凰网 联合早报 更多&gt;&gt; 邮箱 163...<font color=#C60A00>百度</font>视频搜索 更多&gt;&gt; 企业推广 | 搜索风云榜 | 关于<font color=#C60A00>百度</font> | 网友反馈 2007 Baidu 使用<font color=#C60A00>百度</font>前必读 京ICP证030173号... <br><font color=#008000>site.baidu.com/ 25K 2007-12-24  </font> - <a href="http://cache.baidu.com/c?word=%B0%D9%B6%C8&url=http%3A//site%2Ebaidu%2Ecom/&p=8e658615d9c00bb413be9b7d45&user=baiduadv" target="_blank" class=m>百度快照</a> <br></font></td></tr></table><br><table border="0" cellpadding="0" cellspacing="0"><tr><td class=f><a href="http://mp3.baidu.com/" target="_blank"><font size="3"><font color=#C60A00>百度</font>MP3——全球最大中文MP3搜索引擎</font></a><br><font size=-1><font color=#C60A00>百度</font>推荐 热门分类 开放专辑 音乐专题 欧美金曲 日韩流行风 平安夜音乐专题New! 手机娱乐: 手机音乐 铃声排行 彩铃...亲情点歌 音乐抢鲜族 Vcan PK大赛火热进行 把<font color=#C60A00>百度</font>设为首页 | 搜索风云榜 | 关于<font color=#C60A00>百度</font> 2007 Baidu 使用<font color=#C60A00>百度</font>前必读... <br><font color=#008000>mp3.baidu.com/ 13K 2007-12-24  </font> - <a href="http://cache.baidu.com/c?word=%B0%D9%B6%C8&url=http%3A//mp3%2Ebaidu%2Ecom/&p=81578616d9c011a05bfcd42646&user=baiduadv" target="_blank" class=m>百度快照</a> <br></font></td></tr></table><br><table border="0" cellpadding="0" cellspacing="0"><tr><td class=f><a href="http://hi.baidu.com/" target="_blank"><font size="3"><font color=#C60A00>百度</font>空间——真我,真朋友:中文世界最真诚的交友社区</font></a><br><font size=-1><font color=#C60A00>百度</font>提供的免费 Blog 空间服务,可发表文章,发布照片,进行个性展示,与网友分享交流。 <br><font color=#008000>hi.baidu.com/ 35K 2007-12-24  </font> - <a href="http://cache.baidu.com/c?word=%B0%D9%B6%C8&url=http%3A//hi%2Ebaidu%2Ecom/&p=8372cd15d9c018f304be9b7d15&user=baiduadv" target="_blank" class=m>百度快照</a> <br><a class="m" target="_blank" href="s?lm=0&si=&rn=10&tn=baiduadv&ie=gb2312&ct=1&wd=%B0%D9%B6%C8%20site%3Ahi%2Ebaidu%2Ecom+&cl=2">hi.baidu.com&nbsp;上的更多结果</a></font></td></tr></table><br><table border="0" cellpadding="0" cellspacing="0"><tr><td class=f><a href="http://tieba.baidu.com/" target="_blank"><font size="3"><font color=#C60A00>百度</font>贴吧——全球最大中文社区</font></a><br><font size=-1><font color=#C60A00>百度</font>故城吧阳光梦想爱心活动 你有创意细胞就出招! 王媞做客贴吧 情侣之间关于钱的7个误区 今日专题:他们,就在我们身边。 他们是些再平凡不过的的人。从不发出声音,也没有什么奢望。生活,从来就没有给他们很多。已经故去的,让我们记住... <br><font color=#008000>tieba.baidu.com/ 24K 2007-12-24  </font> - <a href="http://cache.baidu.com/c?word=%B0%D9%B6%C8&url=http%3A//tieba%2Ebaidu%2Ecom/&p=8272c64ad59914ee07bd9b7d0d43&user=baiduadv" target="_blank" class=m>百度快照</a> <br><a class="m" target="_blank" href="s?lm=0&si=&rn=10&tn=baiduadv&ie=gb2312&ct=1&wd=%B0%D9%B6%C8%20site%3Atieba%2Ebaidu%2Ecom+&cl=2">tieba.baidu.com&nbsp;上的更多结果</a></font></td></tr></table><br><table border="0" cellpadding="0" cellspacing="0"><tr><td class=f><a href="http://map.baidu.com/" target="_blank"><font size="3"><font color=#C60A00>百度</font>地图搜索</font></a><br><font size=-1>新闻 网页 贴吧 知道 MP3 图片 地图 帮助 您的浏览器禁用了javascript,请修改浏览器设置后重试! 2006 Baidu 免责声明 使用条款 与<font color=#C60A00>百度</font>对话 - 地图服务 Mapbar.com... <br><font color=#008000>map.baidu.com/  2K 2007-12-24  </font> - <a href="http://cache.baidu.com/c?word=%B0%D9%B6%C8&url=http%3A//map%2Ebaidu%2Ecom/&p=8e36df16d9c000e708e2973617&user=baiduadv" target="_blank" class=m>百度快照</a> <br></font></td></tr></table><br><table border="0" cellpadding="0" cellspacing="0"><tr><td class=f><a href="http://zhidao.baidu.com/" target="_blank"><font size="3"><font color=#C60A00>百度</font>知道——全球最大中文互动问答平台</font></a><br><font size=-1>如要投诉或提出意见建议,请到<font color=#C60A00>百度</font>知道投诉吧反馈。 本期主题知识 本期主题:圣诞狂欢夜 随着“铃儿响叮当”的旋律,圣诞翩然而至。舒展你的肢体,狂欢吧! 进入本期主题&gt;&gt; 公告区 如何使用知道 知恩感恩获奖公告new 知书答礼获奖名单 提高警惕... <br><font color=#008000>zhidao.baidu.com/ 44K 2007-12-24  </font> - <a href="http://cache.baidu.com/c?word=%B0%D9%B6%C8&url=http%3A//zhidao%2Ebaidu%2Ecom/&p=9b74c64ad58306ff57ee88124d&user=baiduadv" target="_blank" class=m>百度快照</a> <br></font></td></tr></table><br><table border="0" cellpadding="0" cellspacing="0"><tr><td class=f><a href="http://union.baidu.com/" target="_blank"><font size="3"><font color=#C60A00>百度</font>联盟-首页</font></a><br><font size=-1>将与主题最相关的<font color=#C60A00>百度</font>竞价文字链投放到您的网站相应的页面。用户点击推广内容,网站主就可以从<font color=#C60A00>百度</font>获得相应的佣金。网站主把<font color=#C60A00>百度</font>搜索框代码投放到任一网页,就可以向其用户提供网站搜索功能。免费拥有<font color=#C60A00>百度</font>搜索服务,零成本的赚钱工具。合作推广... <br><font color=#008000>union.baidu.com/ 11K 2007-12-24  </font> - <a href="http://cache.baidu.com/c?word=%B0%D9%B6%C8&url=http%3A//union%2Ebaidu%2Ecom/&p=8e6ec54ad5915dfc57eed3284e&user=baiduadv" target="_blank" class=m>百度快照</a> <br><a class="m" target="_blank" href="s?lm=0&si=&rn=10&tn=baiduadv&ie=gb2312&ct=1&wd=%B0%D9%B6%C8%20site%3Aunion%2Ebaidu%2Ecom+&cl=2">union.baidu.com&nbsp;上的更多结果</a></font></td></tr></table><br><table border="0" cellpadding="0" cellspacing="0"><tr><td class=f><a href="http://image.baidu.com/" target="_blank"><font size="3"><font color=#C60A00>百度</font>图片——全球最大中文图片库</font></a><br><font size=-1>小图 壁纸 帮助 高级 热点目录: 爆笑趣图 精品推荐 美女明星 卡通动漫 精美壁纸 电影电视 风景名胜 手机娱乐: 热辣彩图 炫彩动画 空间图片,可以批量上传! 把<font color=#C60A00>百度</font>设为首页 | 搜索风云榜 | 关于<font color=#C60A00>百度</font> 2007 Baidu 使用<font color=#C60A00>百度</font>前必读 ... <br><font color=#008000>image.baidu.com/  8K 2007-12-24  </font> - <a href="http://cache.baidu.com/c?word=%B0%D9%B6%C8&url=http%3A//image%2Ebaidu%2Ecom/&p=9b769a4694d911a05ba6ce204a&user=baiduadv" target="_blank" class=m>百度快照</a> <br></font></td></tr></table><br><table border="0" cellpadding="0" cellspacing="0"><table><br>
    </textarea>
    <div id="show">
    </div>
    <script>
    var reg=/[\s\S]*?(<td\sclass=f>(?:(?!<\/td>)[\s\S])+<\/td>)(?:(?!<td\sclass=f>)[\s\S])+/gi;
    var txt=document.getElementById("txt").value;
    var str=txt.replace(reg,"$1<hr />");
    document.getElementById("show").innerHTML=str;
    </script>
      

  3.   

    http://topic.csdn.net/u/20071220/14/7e73c0a7-dd43-44da-ad07-b9a79a46a680.html
      

  4.   

    再进一步<script>
    /* 第一步 提取内容部分 */
    var reg=/[\s\S]*?<td\sclass=f>((?:(?!<\/td>)[\s\S])+)<\/td>(?:(?!<td\sclass=f>)[\s\S])+/gi;
    var txt=document.getElementById("txt").value;
    var str=txt.replace(reg,"$1★<br>");/* 第二步 去掉除<br>外的所有标签 */
    var reg2=/<\/?(?:(?!br|>)[\s\S])+[^>]*>/ig;
    str=str.replace(reg2,"");/* 第三步 去掉后面有"百度快照"等字眼的部分 */
    var reg3=/(?:<br>(?:(?!<br>).)*){2}★/ig;
    str=str.replace(reg3,"<hr />");document.getElementById("show").innerHTML=str;
    </script>
      

  5.   

    把获取到的网页全部代码复制进textarea,再点按钮~~<script>
    <textarea id="txt"></textarea>
    <div id="show">
    </div>
    <input type="button" value="分析" onclick="fenxi()" />
    <script>
    function fenxi(){
    /* 第一步 提取内容部分 */
    var reg=/[\s\S]*?<td\sclass=f>((?:(?!<\/td>)[\s\S])+)<\/td>(?:(?!<td\sclass=f>)[\s\S])+/gi;
    var txt=document.getElementById("txt").value;
    var str=txt.replace(reg,"$1★<br>");/* 第二步 去掉除<br>外的所有标签 */
    var reg2=/<\/?(?:(?!br|>)[\s\S])+[^>]*>/ig;
    str=str.replace(reg2,"");/* 第三步 去掉后面有"百度快照"等字眼的部分 */
    var reg3=/(?:<br>(?:(?!<br>).)*){2}★/ig;
    str=str.replace(reg3,"<hr />");document.getElementById("show").innerHTML=str;
    }
    </script>
      

  6.   

    谢谢 he_8134 我还想问一下 我想把搜索到的资料进行内容分类
     例如:
    标题(如“百度网址大全”) 文本内容(如“百度   新浪   搜狐   网易   腾讯QQ   更多> >   新闻   新浪新闻   人民网   新华网   中央电视台   凤凰网   联合早报   更多> >   邮箱   163...百度视频搜索   更多> >   企业推广   ¦   搜索风云榜   ¦   关于百度   ¦   网友反馈   2007   Baidu   使用百度前必读   京ICP证030173号...   
    ”)有没有什么好的办法 把他们写入数据库
      

  7.   

    怎么从百度那里掏数据就不说了,以下前提是保存到本地后的文件~~手写的,我这里没运行环境,没调试~~class BaiduDataInfo{
        public string Title;
        public string Content;
        public BaiduDataInfo(string title,string content){
            this.Title=title;
            this.Content=content;
        }
        public override string ToString(){
            string.Format("标题:{0}\n内容:{1}\n",Title,Content);
        }
    }
    void Main(){
        TextReader tr=new StreamReader(@"d:\baidu.html");
        string text=tr.ReadToEnd();
        Regex reg=new Regex(@".*?<td\sclass=f>((?:(?!</td>).)+)</td>(?:(?!<td\sclass=f>).)+",RegexOptions.IgnoreCase|RegexOptions.Singleline|RegexOptions.Compiled);
        text=reg.Replace(text,"$1★");
        Regex reg2=new Regex(@"</?(?:(?!br|>).)+[^>]*>",RegexOptions.IgnoreCase|RegexOptions.Singleline|RegexOptions.Compiled);
        text=reg2.Replace(text,"");
        Regex reg3=new Regex(@"(?<title>(?:(?!<br>).)+)<br>(?<content>(?:(?!<br>).)+)<br>[^★]*★",RegexOptions.IgnoreCase|RegexOptions.Singleline|RegexOptions.Compiled);
        List<BaiduDataInfo> list=new List<BaiduDataInfo>();
        foreach(Match m in reg3.Matches(text)){
            string title=m.Groups["title"].Value;
            string content=m.Groups["content"].Value;
            list.Add(new BaiduDataInfo(title,content));
        }
        foreach(BaiduDataInfo data in list){
            Console.WriteLine(data);
        }
        Console.Read();
    }
      

  8.   

    调试通过了~~using System;
    using System.Collections.Generic;
    using System.Text;
    using System.IO;
    using System.Text.RegularExpressions;
    namespace ConsoleApplication1
    {
        class BaiduDataInfo
        {
            public string Title;
            public string Content;
            public BaiduDataInfo(string title, string content)
            {
                this.Title = title;
                this.Content = content;
            }
            public override string ToString()
            {
                return string.Format("标题:{0}\n内容:{1}\n", Title, Content);
            }
        }
        class Program
        {
            static void Main(string[] args)
            {
                TextReader tr = new StreamReader(@"d:\baidu.html",Encoding.GetEncoding("gb2312"));
                string text = tr.ReadToEnd();
                tr.Close();
                tr.Dispose();
                Regex reg = new Regex(@".*?<td\sclass=f>((?:(?!</td>).)+)</td>(?:(?!<td\sclass=f>).)+", RegexOptions.IgnoreCase | RegexOptions.Singleline | RegexOptions.Compiled);
                text = reg.Replace(text, "$1★");
                Regex reg2 = new Regex(@"</?(?:(?!br|>).)+[^>]*>", RegexOptions.IgnoreCase | RegexOptions.Singleline | RegexOptions.Compiled);
                text = reg2.Replace(text, "");
                //替换掉html空格&nbsp 和 < >括号&lt &gt
                text = Regex.Replace(text, @"&[nN][bB][sS][pP];", " ");
                text = Regex.Replace(text, @"&[lL][tT];", "<");
                text = Regex.Replace(text, @"&[gG][tT];", ">");
                Regex reg3 = new Regex(@"(?<title>(?:(?!<br>).)+)<br>(?<content>(?:(?!<br>).)+)<br>[^★]*★", RegexOptions.IgnoreCase | RegexOptions.Singleline | RegexOptions.Compiled);
                List<BaiduDataInfo> list = new List<BaiduDataInfo>();
                foreach (Match m in reg3.Matches(text))
                {
                    string title = m.Groups["title"].Value;
                    string content = m.Groups["content"].Value;
                    list.Add(new BaiduDataInfo(title, content));
                }
                foreach (BaiduDataInfo data in list)
                {
                    Console.WriteLine(data);
                }
                Console.Read();
            }
        }
    }