求匹配网站的正则

ypss_milo 2012-02-17 09:43:37
<li>
<div class="info">
<a class="title_n" href="http://www.tootoomart.com/product-4134493-Men+the+new+Pure+paul+Sminth+Smith+sweater+16+colors+sweaters/" target="_blank"><h2>Men the new Pure paul Sminth Smith sweater 16 colors...</h2></a>
<p class="info">Men the new Pure paul Sminth Smith sweater 16 colors sweaters</p>
<div class="infoBox wrapClear">
<div class="supplier">Wholesaler: <a href="/seller-jingjinghaoyun888/">jingjinghaoyun888</a> <b class="star6"><img src="http://img.ttmimg.com/www/img/090514/transparent-pixel.gif" width="16" height="16" title="Feedback Score is 1-50"/></b></div>
<span id="isSellerOnline_jingjinghaoyun888_1"></span>
</div>
</div>
<div class="priceArea">
<p class="price1" id="price">$16.36~$16.58/Piece</p>
<div class="items">
<p class="price2">$163.59~$165.73/Lot</p>
<p class="priceInfo">(10 s per lot)</p>
</div>
</div>
<p class="images"><a href="http://www.tootoomart.com/product-4134493-Men+the+new+Pure+paul+Sminth+Smith+sweater+16+colors+sweaters/" title="Men the new Pure paul Sminth Smith sweater 16 colors sweaters" alt="Men the new Pure paul Sminth Smith sweater 16 colors sweaters" target="_blank"><img src="http://img.ttmimg.com/images/product/images/091219/90/0912190632381314441bmzaz_130.jpg" alt="Men the new Pure paul Sminth Smith sweater 16 colors sweaters" onload="if((this.width>=this.height)&&(this.width>=130)) {this.resized=true; this.width=130;} if((this.height>this.width)&&(this.height>=130)) {this.resized=true; this.height=130;}" onerror='this.onerror="";this.src="/images/www/nophoto_small.gif"' ptype="photo"/></a></p>
</li>

我要匹配这里面所有P标签里的字 除(10 s per lot) 和$163.59~$165.73/Lot外 和图片的src 求匹配的正则
...全文
135 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
ypss_milo 2012-02-20
  • 打赏
  • 举报
回复
@pmars: name1和name2 取值有点问题 其他的都正常啊 还有就是上面的HTML代码只是一个商品的信息 一个页面一般有比较多的商品 怎么直接取到了最后一个商品啊 不能循环取啊
ypss_milo 2012-02-20
  • 打赏
  • 举报
回复
我感觉还是那正则的问题 求代码
ypss_milo 2012-02-20
  • 打赏
  • 举报
回复
string url = "http://www.tootoomart.com/wholesale-hair+removal/";
string charset = "utf-8";
string html = GetHtmlSource(url, charset);
string reg =@"(?s)<li[^>]*>.*?<h2>(?<name1>(?!</h2>).*)</h2>.*?<p(?!class).*class=[""]info[""]>(?<name2>.*?)</p>.*?<div\s*class=[""]supplier[""]>.*?<a[^>]*>(?<name3>.*?)</a>.*?<p\s*class=[""]price1[""]\s*id=[""]price[""]>(?<name4>.*?)</p>.*?<p\s*class=[""]images[""]>.*?<img\s*src=[""](?<name5>.*?)[""].*?</li>";
Regex regex = new Regex(reg, RegexOptions.None);
MatchCollection matchCollection = regex.Matches(html);
for (int i = 0; i < matchCollection.Count; i++)
{
Match match = matchCollection[i];
string name = match.Groups["name1"].Value;
name = name.Replace("'", "''");
}

这是代码name 里面取出来一大推HTML代码啊 不是我要的那一句啊 你们都测试时对的吗?求高手代码
xnlm2005 2012-02-17
  • 打赏
  • 举报
回复
参考楼上的高手,给你个完整的:string str = @"(?s)<li[^>]*>.*?<h2>(?<name1>(?!</h2>).*)</h2>.*?<p(?!class).*class=[""]info[""]>(?<name2>.*?)</p>.*?<div\s*class=[""]supplier[""]>.*?<a[^>]*>(?<name3>.*?)</a>.*?<p\s*class=[""]price1[""]\s*id=[""]price[""]>(?<name4>.*?)</p>.*?<p\s*class=[""]images[""]>.*?<img\s*src=[""](?<name5>.*?)[""].*?</li>";直接复制,然后取值就可以了。
q107770540 2012-02-17
  • 打赏
  • 举报
回复
你想要神马?
规则要说清楚
zzzzv0 2012-02-17
  • 打赏
  • 举报
回复
3楼的能用啊,楼主前面加个(?s)
ypss_milo 2012-02-17
  • 打赏
  • 举报
回复
还是你哈 报错了
pmars 2012-02-17
  • 打赏
  • 举报
回复
try
<li[^>]*>.*?<h2>(?<name1>(?!</h2>).*)</h2>.*?<p(?!class).*class=['"]info['"]>(?<name2>.*?)</p>.*?<div\s*class=['"]supplier['"]>.*?<a[^>]*>(?<name3>.*?)</a>.*?<p\s*class=['"]price1['"]\s*id=['"]price['"]>(?<name4>.*?)</p>.*?<p\s*class=['"]images['"]>.*?<img\s*src=['"](?<name5>.*?)['"].*?</li>
ypss_milo 2012-02-17
  • 打赏
  • 举报
回复
我需要的的<h2>里面的一个值取个名字《name1》 <p class="info">里面的值《name2》

<div class="supplier">这个层里面的《a》标签的值《name3》 <p class="price1" id="price">里面的值《name4》 取<p class="images">里面的《ing》里的src 取名<name5> 这写肯定都是《li》的

110,534

社区成员

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

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

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