正则求救!!! 小第不会正则现要做一个功能请教大家拉!!

xr396464010 2010-01-05 03:02:47
下面一共有2个DIV 我要取出下面DIV中图片地址例如: http://img10.360buyimg.com/S1/318/8fe850ba-13fc-4a6f-8f63-f744c5e53a58.jpg

在这先谢谢大家了!!!

<div class="Product_Name"><h1>三菱(Mitsubishi) CD-R 52速 700M 白金 台产 盒装10片 刻录盘</h1><font color="#FF0000" ></font></div><div id="Product_Intro_Left" >
<div id="Product_BigImage" class="jqzoom" onclick = "window.open('http://www.360buy.com/bigimage.aspx?id=100033')">
<img onerror = "this.src='http://www.360buy.com/images/none/none_347.gif'" alt="三菱(Mitsubishi) CD-R 52速 700M 白金 台产 盒装10片 刻录盘" src="http://img10.360buyimg.com/S1/318/8fe850ba-13fc-4a6f-8f63-f744c5e53a58.jpg" width="349" jqimg="http://img10.360buyimg.com/S0/318/8fe850ba-13fc-4a6f-8f63-f744c5e53a58.jpg"/>
</div>

<div id="Product_LittleImage"><ul id="mycarousel" class="jcarousel-skin-tango"><li>
<img onerror = "this.src='http://www.360buy.com/images/none/none_50.gif'" alt="三菱(Mitsubishi) CD-R 52速 700M 白金 台产 盒装10片 刻录盘" src="http://img10.360buyimg.com/S5/318/8fe850ba-13fc-4a6f-8f63-f744c5e53a58.jpg" name="318/8fe850ba-13fc-4a6f-8f63-f744c5e53a58.jpg"/>
</li>
<li><img onerror = "this.src='http://www.360buy.com/images/none/none_50.gif'" alt="三菱(Mitsubishi) CD-R 52速 700M 白金 台产 盒装10片 刻录盘" src="http://img10.360buyimg.com/S5/119/8c2962d1-f2a8-403e-9e5b-1d0993c5320c.jpg" name="119/8c2962d1-f2a8-403e-9e5b-1d0993c5320c.jpg"/></li><li>
<img onerror = "this.src='http://www.360buy.com/images/none/none_50.gif'" alt="三菱(Mitsubishi) CD-R 52速 700M 白金 台产 盒装10片 刻录盘" src="http://img10.360buyimg.com/S5/813/303fca2a-7e57-4cb8-8d9b-1ab6c74e5533.jpg" name="813/303fca2a-7e57-4cb8-8d9b-1ab6c74e5533.jpg"/></li><li>
<img onerror = "this.src='http://www.360buy.com/images/none/none_50.gif'" alt="三菱(Mitsubishi) CD-R 52速 700M 白金 台产 盒装10片 刻录盘" src="http://img10.360buyimg.com/S5/653/b6657aad-fa9b-4e5b-bedb-be764d28c7bb.jpg" name="653/b6657aad-fa9b-4e5b-bedb-be764d28c7bb.jpg"/></li><li><img onerror = "this.src='http://www.360buy.com/images/none/none_50.gif'" alt="三菱(Mitsubishi) CD-R 52速 700M 白金 台产 盒装10片 刻录盘" src="http://img10.360buyimg.com/S5/347/24c5a7bc-db4c-4b1e-b7ca-732ee9786e83.jpg" name="347/24c5a7bc-db4c-4b1e-b7ca-732ee9786e83.jpg"/></li></ul></div>
...全文
91 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
xr396464010 2010-01-05
  • 打赏
  • 举报
回复
问题已解决!! 谢谢大家!!!
xr396464010 2010-01-05
  • 打赏
  • 举报
回复
第一个ID写错了 应该是 Product_BigImage
xr396464010 2010-01-05
  • 打赏
  • 举报
回复
@(?is)(?<=<div id="Product_Big[^<>]"") 开头应该这么写,后面的我不知道写,我就是想指定丛id="Product_Big 这个DIV开始找 找到第二个DIV结束, 一共是找二个DIV里面的全部IMG

就是这两个DIV里面的全部IMG 我要取的内容就是 SRC 后面这个HTTP 全路径 src="http://img10.360buyimg.com/S1/318/8fe850ba-13fc-4a6f-8f63-f744c5e53a58.jpg"
*************************************************

<div id="Product_BigImage" class="jqzoom" onclick = "window.open('http://www.360buy.com/bigimage.aspx?id=100033')">
<img onerror = "this.src='http://www.360buy.com/images/none/none_347.gif'" alt="三菱(Mitsubishi) CD-R 52速 700M 白金 台产 盒装10片 刻录盘" src="http://img10.360buyimg.com/S1/318/8fe850ba-13fc-4a6f-8f63-f744c5e53a58.jpg" width="349" jqimg="http://img10.360buyimg.com/S0/318/8fe850ba-13fc-4a6f-8f63-f744c5e53a58.jpg"/>
</div>

<div id="Product_LittleImage"> <ul id="mycarousel" class="jcarousel-skin-tango"> <li>
<img onerror = "this.src='http://www.360buy.com/images/none/none_50.gif'" alt="三菱(Mitsubishi) CD-R 52速 700M 白金 台产 盒装10片 刻录盘" src="http://img10.360buyimg.com/S5/318/8fe850ba-13fc-4a6f-8f63-f744c5e53a58.jpg" name="318/8fe850ba-13fc-4a6f-8f63-f744c5e53a58.jpg"/>
</li>
<li> <img onerror = "this.src='http://www.360buy.com/images/none/none_50.gif'" alt="三菱(Mitsubishi) CD-R 52速 700M 白金 台产 盒装10片 刻录盘" src="http://img10.360buyimg.com/S5/119/8c2962d1-f2a8-403e-9e5b-1d0993c5320c.jpg" name="119/8c2962d1-f2a8-403e-9e5b-1d0993c5320c.jpg"/> </li> </ul> </div>
liherun 2010-01-05
  • 打赏
  • 举报
回复
你到底想搞什么老大?
把你的实例发上来吧,这样搞一会换一下
xr396464010 2010-01-05
  • 打赏
  • 举报
回复
不太会正则,虚心向大家请教了。。
xr396464010 2010-01-05
  • 打赏
  • 举报
回复
@"(?is)src=""http[^>]*?(jpg|gif)""" 这句能否加个指定的条件开始或结束, 这样子可能取的是整个页面的了

比如我页面有很多DIV 而我只要取下面的DIV3 和DIV4里面的所有IMG 我是这样写的大家帮忙看下了
例如
<div> 这是div1内容 </div>
<div> 这是div2内容 </div>
<div id="div3"> 这是div3内容 </div>
<div id="div4"> 这是div4内容 </div>
<div> 这是div5内容 </div>
<div> 这是div6内容 </div>
jimh 2010-01-05
  • 打赏
  • 举报
回复
@"(?is)src=""http[^>]*?(jpg|gif)"""
liherun 2010-01-05
  • 打赏
  • 举报
回复
你图片不都是http开头的嘛?
你试试
xr396464010 2010-01-05
  • 打赏
  • 举报
回复
(@"(?is)http[^>]*?(jpg|gif)"); 这个会不会连这个也会找到 onerror = ""this.src='http://www.360buy.com/images/none/none_347.gif'""
因为这中间也人HTTP呀 但是我只要 SRC=“后面这个完整的链接地址”
xr396464010 2010-01-05
  • 打赏
  • 举报
回复
能够按class=""Product_Name开头么, 因为面页会有很多DIV 要指定一个,这样比较准确点, 谢谢了呀
liherun 2010-01-05
  • 打赏
  • 举报
回复
            string str = @"<div class=""Product_Name""> <h1>三菱(Mitsubishi) CD-R 52速 700M 白金 台产 盒装10片 刻录盘 </h1> <font color=""#FF0000"" > </font> </div> <div id=""Product_Intro_Left"" > 
<div id=""Product_BigImage"" class=""jqzoom"" onclick = ""window.open('http://www.360buy.com/bigimage.aspx?id=100033')"">
<img onerror = ""this.src='http://www.360buy.com/images/none/none_347.gif'"" alt=""三菱(Mitsubishi) CD-R 52速 700M 白金 台产 盒装10片 刻录盘"" src=""http://img10.360buyimg.com/S1/318/8fe850ba-13fc-4a6f-8f63-f744c5e53a58.jpg"" width=""349"" jqimg=""http://img10.360buyimg.com/S0/318/8fe850ba-13fc-4a6f-8f63-f744c5e53a58.jpg""/>
</div>
";
Regex reg = new Regex(@"(?is)http[^>]*?(jpg|gif)");
foreach (Match m in reg.Matches(str))
{
MessageBox.Show(m.Value);
}

110,525

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧