http://www.sufeinet.com/plugin.php?id=keke_group

苏飞论坛

 找回密码
 马上注册

QQ登录

只需一步,快速开始

分布式系统框架(V2.0) 轻松承载百亿数据,千万流量!讨论专区 - 源码下载 - 官方教程

HttpHelper爬虫框架(V2.7-含.netcore) HttpHelper官方出品,爬虫框架讨论区 - 源码下载 - 在线测试和代码生成

HttpHelper爬虫类(V2.0) 开源的爬虫类,支持多种模式和属性 源码 - 代码生成器 - 讨论区 - 教程- 例子

查看: 4330|回复: 8

[其他] 求一个正则表达式

[复制链接]
发表于 2014-5-5 13:46:52 | 显示全部楼层 |阅读模式
5金钱
[HTML] 纯文本查看 复制代码
<tr> <td class="left"> <div class="list-group"> <a href="http://item.taobao.com:80/item.htm?id=37435847725" class="img" target="_blank"><img src="http://img02.taobaocdn.com/bao/uploaded/i2/T15MivFzxcXXXXXXXX_!!0-item_pic.jpg_80x80.jpg"></a> <ul class="attr"> <li class="title">  <a href="http://item.taobao.com:80/item.htm?id=37435847725" target="_blank">范大师客供120支丝光棉 立体烫钻经款 V领修身百搭 <span class="H">男式</span>短袖<span class="H">T恤</span></a> </li> <li class="seller"> <span class="color-grey">掌柜:大_山</span> </li> <li> <a href="#!/promo/self/shop_detail?userNumberId=18291375" mx-mouseover="shopinfo_show{biz30day:2,commentCount:4,userNumberId:18291375}" mx-mouseout="shopinfo_hide" class="color-blue" target="_blank" atp="{ptype:'items',ctype:'shop_detail'}" mx-owner="magix_vf_items_list">店铺推广详情>></a> </li> </ul> </div> </td> <td class="left" width="70">--</td> <td class="left" width="70">¥248.00</td> <td class="center" width="80"><span class="color-green">5.00%</span></td> <td class="center" width="70"><span class="green">¥12.40</span></td> <td class="center" width="90">2件</td> <td class="center" width="110">¥17.85</td> <td class="center" width="110"> <div class="operation"> <p><a class="btn btn-blue" href="#" mx-click="zone{auctionId:37435847725,codeType:self_items}" mx-owner="magix_vf_items_list">立即推广</a></p>  <p><a href="#" class="has-campaign" mx-click="campaign{userNumberId:18291375,index:34}" atp="{ptype:'items',ctype:'more_campaign'}" mx-owner="magix_vf_items_list">获取更高佣金<i class="iconfont">?</i></a></p>  </div> </td> </tr>


[HTML] 纯文本查看 复制代码
 <a href="http://item.taobao.com:80/item.htm?id=37435847725" class="img" target="_blank"> 
 取:[url]http://item.taobao.com:80/item.htm?id=37435847725[/url]

<img src="http://img02.taobaocdn.com/bao/uploaded/i2/T15MivFzxcXXXXXXXX_!!0-item_pic.jpg_80x80.jpg">
取:[img]http://img02.taobaocdn.com/bao/uploaded/i2/T15MivFzxcXXXXXXXX_!!0-item_pic.jpg_80x80.jpg[/img]

<li class="title">  <a href="http://item.taobao.com:80/item.htm?id=37435847725" target="_blank">范大师客供120支丝光棉 立体烫钻经款 V领修身百搭 <span class="H">男式</span>短袖<span class="H">T恤</span></a> </li>
取:<a href="http://item.taobao.com:80/item.htm?id=37435847725" target="_blank">范大师客供120支丝光棉 立体烫钻经款 V领修身百搭 <span class="H">男式</span>短袖<span class="H">T恤</span></a>

<li> <a href="#!/promo/self/shop_detail?userNumberId=18291375" mx-mouseover="shopinfo_show{biz30day:2,commentCount:4,userNumberId:18291375}" mx-mouseout="shopinfo_hide" class="color-blue" target="_blank" atp="{ptype:'items',ctype:'shop_detail'}" mx-owner="magix_vf_items_list">店铺推广详情>></a> </li>
取:18291375

<td class="left" width="70">¥248.00</td>(这是第三的一个td)
取:248.00

<span class="green">¥12.40</span>

取:12.40


需要一次性提取,因为一页中还有很多这样的tr标签,谢谢各位大神了。


最佳答案

查看完整内容

[mw_shl_code=csharp,true] private string GetValues(string Source) { try { string rStr = ""; Regex r = new Regex("((href=\"|src=\")(?[http].*?)\")|title\">(?.*?)|userNumberId=(?.*?)\"|¥(?.*?)


1. 开通SVIP会员,免费下载本站所有源码,不限次数据,不限时间
2. 加官方QQ群,加官方微信群获取更多资源和帮助
3. 找站长苏飞做网站、商城、CRM、小程序、App、爬虫相关、项目外包等点这里
发表于 2014-5-5 13:46:53 | 显示全部楼层
本帖最后由 cload 于 2014-5-5 23:41 编辑

[C#] 纯文本查看 复制代码
        private string GetValues(string Source)
        {
            try
            {
                string rStr = "";
                Regex r = new Regex("((href=\"|src=\")(?<value>[http].*?)\")|title\">(?<value>.*?)</a>|userNumberId=(?<value>.*?)\"|¥(?<value>.*?)<");
                Match m = r.Match(Source);
                while (m.Success)
                {
                    rStr += m.Groups["value"].Value.Trim() + "\r\n";
                    m = m.NextMatch();
                }
                return rStr;
            }
            catch
            {
                return "";
            }
        }
回复

使用道具 举报

发表于 2014-5-5 14:10:12 | 显示全部楼层
(¥(.*?)<)
回复

使用道具 举报

 楼主| 发表于 2014-5-5 14:24:50 | 显示全部楼层

需要一次性把所有的需要的内容都提取出来啊  谢谢你
回复

使用道具 举报

发表于 2014-5-5 14:29:53 | 显示全部楼层
你表达的较乱,我没能充分理解。
回复

使用道具 举报

 楼主| 发表于 2014-5-5 14:33:35 | 显示全部楼层
cload 发表于 2014-5-5 14:29
你表达的较乱,我没能充分理解。

源文本:
[HTML] 纯文本查看 复制代码
<tr> <td class="left"> <div class="list-group"> <a href="http://item.taobao.com:80/item.htm?id=37435847725" class="img" target="_blank"><img src="http://img02.taobaocdn.com/bao/uploaded/i2/T15MivFzxcXXXXXXXX_!!0-item_pic.jpg_80x80.jpg"></a> <ul class="attr"> <li class="title">  <a href="http://item.taobao.com:80/item.htm?id=37435847725" target="_blank">范大师客供120支丝光棉 立体烫钻经款 V领修身百搭 <span class="H">男式</span>短袖<span class="H">T恤</span></a> </li> <li class="seller"> <span class="color-grey">掌柜:大_山</span> </li> <li> <a href="#!/promo/self/shop_detail?userNumberId=18291375" mx-mouseover="shopinfo_show{biz30day:2,commentCount:4,userNumberId:18291375}" mx-mouseout="shopinfo_hide" class="color-blue" target="_blank" atp="{ptype:'items',ctype:'shop_detail'}" mx-owner="magix_vf_items_list">店铺推广详情>></a> </li> </ul> </div> </td> <td class="left" width="70">--</td> <td class="left" width="70">¥248.00</td> <td class="center" width="80"><span class="color-green">5.00%</span></td> <td class="center" width="70"><span class="green">¥12.40</span></td> <td class="center" width="90">2件</td> <td class="center" width="110">¥17.85</td> <td class="center" width="110"> <div class="operation"> <p><a class="btn btn-blue" href="#" mx-click="zone{auctionId:37435847725,codeType:self_items}" mx-owner="magix_vf_items_list">立即推广</a></p>  <p><a href="#" class="has-campaign" mx-click="campaign{userNumberId:18291375,index:34}" atp="{ptype:'items',ctype:'more_campaign'}" mx-owner="magix_vf_items_list">获取更高佣金<i class="iconfont">?</i></a></p>  </div> </td> </tr>


需要提取的数据:
[HTML] 纯文本查看 复制代码
 <a href="http://item.taobao.com:80/item.htm?id=37435847725" class="img" target="_blank"> 
 取:[url]http://item.taobao.com:80/item.htm?id=37435847725[/url]

<img src="http://img02.taobaocdn.com/bao/uploaded/i2/T15MivFzxcXXXXXXXX_!!0-item_pic.jpg_80x80.jpg">
取:[img]http://img02.taobaocdn.com/bao/uploaded/i2/T15MivFzxcXXXXXXXX_!!0-item_pic.jpg_80x80.jpg[/img]

<li class="title">  <a href="http://item.taobao.com:80/item.htm?id=37435847725" target="_blank">范大师客供120支丝光棉 立体烫钻经款 V领修身百搭 <span class="H">男式</span>短袖<span class="H">T恤</span></a> </li>
取:<a href="http://item.taobao.com:80/item.htm?id=37435847725" target="_blank">范大师客供120支丝光棉 立体烫钻经款 V领修身百搭 <span class="H">男式</span>短袖<span class="H">T恤</span></a>

<li> <a href="#!/promo/self/shop_detail?userNumberId=18291375" mx-mouseover="shopinfo_show{biz30day:2,commentCount:4,userNumberId:18291375}" mx-mouseout="shopinfo_hide" class="color-blue" target="_blank" atp="{ptype:'items',ctype:'shop_detail'}" mx-owner="magix_vf_items_list">店铺推广详情>></a> </li>
取:18291375

<td class="left" width="70">¥248.00</td>(这是第三的一个td)
取:248.00

<span class="green">¥12.40</span>
取:12.40


需要一次性提取,因为一页中还有很多这样的tr标签
回复

使用道具 举报

 楼主| 发表于 2014-5-6 09:40:05 | 显示全部楼层
cload 发表于 2014-5-5 13:46
[C#] 纯文本查看 复制代码
        private string GetValues(string Source)
        {
            try ...[/quote]

谢谢你  在i给的表达式基础上我修改了一下   
[mw_shl_code=html,true]((href=\")(?<http>[http].*?)\")[\s\S]*?((src=\")(?<img>.*?)\")[\s\S]*?title\">(?<title>.*?)</a>[\s\S]*?userNumberId=(?<userID>.*?)\"[\s\S]*?¥(?<Money>.*?)<[\s\S]*?green">¥(?<Green>.*?)<




只是不知道下图中框起来的部分怎么给去掉

QQ截图20140506093656.png
回复

使用道具 举报

发表于 2014-5-6 10:44:19 | 显示全部楼层
?<http>其中http为获取组的名称,在你的需求中要统一下名称。
我写的那个取出来后,就没有你说的问题,你再看看。
回复

使用道具 举报

 楼主| 发表于 2014-5-6 10:48:27 | 显示全部楼层
cload 发表于 2014-5-6 10:44
?其中http为获取组的名称,在你的需求中要统一下名称。
我写的那个取出来后,就没有你说的问题,你再看看 ...

非常感谢你帮了我的大忙,真的太感谢你啦!

非常感谢你   

现在对正则表达式有点理解了   简单的会摸索着写了  谢谢
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 马上注册

本版积分规则

QQ|手机版|小黑屋|手机版|联系我们|关于我们|广告合作|苏飞论坛 ( 豫ICP备18043678号-2)

GMT+8, 2024-5-21 09:36

© 2014-2021

快速回复 返回顶部 返回列表