首页 新闻 搜索 专区 学院

html正则表达式

0
悬赏园豆:100 [已解决问题] 解决于 2015-04-22 14:30

html标签如下:

<div id="content_left">
<div class="result c-container " id="1" srcid="1599" tpl="se_com_default" data-click="{&quot;rsv_bdr&quot;:&quot;0&quot;,&quot;rsv_cd&quot;:&quot;pt:40520|vLevel:3&quot;,&quot;p5&quot;:1}"><h3 class="t"><a data-click="{
'F':'778717EA',
'F1':'9D73F1E4',
'F2':'4CA6DE6B',
'F3':'54E5243F',
'T':'1429179240',
'y':'37DCEFFD'

}" href="http://www.baidu.com/link?url=qACtFe5IWe267hSUPr_ggzyp_uZXYJm15uE1SBbsmOD6O4OxQpiKxe_h2vliicIPo0dXSRsb22jDBYTiRuNPya" target="_blank"><em>大观园</em>,北京<em>大观园</em>攻略/地址/图片/门票 </a></h3><div class="c-row c-gap-top-small"><div class="general_image_pic c-span6"><a class="c-img6" style="height:75px" href="http://www.baidu.com/link?url=qACtFe5IWe267hSUPr_ggzyp_uZXYJm15uE1SBbsmOD6O4OxQpiKxe_h2vliicIPo0dXSRsb22jDBYTiRuNPya" target="_blank"><img class="c-img c-img6" src="https://ss0.baidu.com/73F1bjeh1BF3odCf/it/u=1858918998,1966881607&amp;fm=96&amp;s=04F478845E5538CE6A3051900300508A" style="height:75px;"></a></div><div class="c-span18 c-span-last"><div class="c-abstract"><em>大观园</em>是一座再现中国古典文学名著《红楼梦》中“<em>大观园</em>”景观的仿古园林,原址为明清两代皇家菜园,明代曾在此设“嘉疏署”。1984年为拍摄电视剧《红楼梦》,经红学...</div><div class="f13"><span class="g"><b>you.ctrip.com</b>/sight/be...&nbsp;</span><div class="c-tools" id="tools_14720738737438748258_1" data-tools="{&quot;title&quot;:&quot;大观园,北京大观园攻略/地址/图片/门票 &quot;,&quot;url&quot;:&quot;http://www.baidu.com/link?url=qACtFe5IWe267hSUPr_ggzyp_uZXYJm15uE1SBbsmOD6O4OxQpiKxe_h2vliicIPo0dXSRsb22jDBYTiRuNPya&quot;}"><a class="c-tip-icon"><i class="c-icon c-icon-triangle-down-g"></i></a></div><span class="c-icons-outer"><span class="c-icons-inner"><span class="c-vline"></span><span class="c-trust-as vstar" data_key="2329391299344843614" hint-data="{&quot;label&quot;:&quot;携程旅游信息技术上海有限公司&quot;,&quot;url&quot;:&quot;http://www.baidu.com/s?wd=you.ctrip.com@v&amp;vmp_ec=41cc6213a4a6ff570ab07476aC55d8fsHdJae94ej2ac29=b05b64Jlp9Sjv30X2dX3d7d4a47945d4c&amp;vmp_ectm=1429156070&amp;from=vs&quot;,&quot;hint&quot;:[{&quot;txt&quot;:&quot;[ecard 99]&quot;,&quot;vlevel&quot;:&quot;3&quot;}]}" hint-type="vstar" render="render"><a href="http://www.baidu.com/s?wd=you.ctrip.com@v&amp;vmp_ec=41cc6213a4a6ff570ab07476aC55d8fsHdJae94ej2ac29=b05b64Jlp9Sjv30X2dX3d7d4a47945d4c&amp;vmp_ectm=1429156070&amp;from=vs" class="c-icon c-icon-v c-icon-v3" target="_blank" data-click="{'title':'vstar','rsv_vlevel':'3'}"></a></span></span></span>&nbsp;-&nbsp;<a data-click="{'rsv_snapshot':'1'}" href="http://cache.baiducontent.com/c?m=9d78d513d9d431a94f9995697d1dc010694381132ba1d6020fd68448e22f0606506793ac27550705a3943a275aed5e5d9ae73605200250e6c6979c0d9de59d7269ce6523716f9b5c598e5eb8cb31748760cb18feaf6eb6e7af2fd2f587899949039d085d21dca588470015c078f0636ba5f9c7&amp;p=8473c64ad4b12dff57ed977542089f&amp;newp=806ec54ad6c04af72aa7c7710f5193231610db2151d2d21427a6d9&amp;user=baidu&amp;fm=sc&amp;query=%B4%F3%B9%DB%D4%B0+you%2Ectrip%2Ecom&amp;qid=e8fd757f0000f5e4&amp;p1=1" target="_blank" class="m">百度快照</a></div></div></div><div class="c-gap-top c-recommend" style="display:none;" data-extquery="北京大观园门票价格&nbsp;北京大观园好玩吗&nbsp;北京大观园图片&nbsp;"><i class="c-icon c-icon-bear-circle c-gap-right-small"></i><span class="c-gray">为您推荐:</span><a href="/s?tn=baiduhome_pg&amp;wd=%E5%8C%97%E4%BA%AC%E5%A4%A7%E8%A7%82%E5%9B%AD%E9%97%A8%E7%A5%A8%E4%BB%B7%E6%A0%BC&amp;rsv_idx=2&amp;ie=utf-8&amp;rsv_crq=7&amp;bs=%E5%A4%A7%E8%A7%82%E5%9B%AD+you.ctrip.com" target="_blank" class="res-gap-right16">北京大观园门票价格</a><a href="/s?tn=baiduhome_pg&amp;wd=%E5%8C%97%E4%BA%AC%E5%A4%A7%E8%A7%82%E5%9B%AD%E5%A5%BD%E7%8E%A9%E5%90%97&amp;rsv_idx=2&amp;ie=utf-8&amp;rsv_crq=7&amp;bs=%E5%A4%A7%E8%A7%82%E5%9B%AD+you.ctrip.com" target="_blank" class="res-gap-right16">北京大观园好玩吗</a><a href="/s?tn=baiduhome_pg&amp;wd=%E5%8C%97%E4%BA%AC%E5%A4%A7%E8%A7%82%E5%9B%AD%E5%9B%BE%E7%89%87&amp;rsv_idx=2&amp;ie=utf-8&amp;rsv_crq=7&amp;bs=%E5%A4%A7%E8%A7%82%E5%9B%AD+you.ctrip.com" target="_blank">北京大观园图片</a></div></div>
</div>

 

需要获取<div id="content_left">中第一条数据,即:id=“1”的div中的
1)<h3>标题,即:<em>大观园</em>,北京<em>大观园</em>攻略/地址/图片/门票
2)<h3><a>的链接:即:http://www.baidu.com/link?url=qACtFe5IWe267hSUPr_ggzyp_uZXYJm15uE1SBbsmOD6O4OxQpiKxe_h2vliicIPo0dXSRsb22jDBYTiRuNPya
3)快照地址:<span class="g"><b>you.ctrip.com</b>/sight/be...&nbsp;</span>,
即:<b>you.ctrip.com</b>/sight/be...&nbsp;


实际是获取<div id="content_left">中第一条数据,即:id=“1”的div中的内容,求正则表达式大神么赐教哦~~!

Alice.Luo的主页 Alice.Luo | 初学一级 | 园豆:112
提问于:2015-04-21 11:03
< >
分享
最佳答案
0

<div[^<]*id="content_left"[^<]*>.*?<div[^<]*id="\d+"[^<]*>.*?<h3[^<]*>[^<]*<a[^<]*href="(.*?)"[^<]*>(.*?)</a>[^<]*</h3>.*?<span[^<]*class="g"[^<]*>(.*?)</span>.*?

 

从group中取

收获园豆:100
Yu | 专家六级 |园豆:12950 | 2015-04-21 17:06

好厉害啊,正则表达式是怎么学习的哦,我都没看不懂。

Alice.Luo | 园豆:112 (初学一级) | 2015-04-22 14:25
其他回答(2)
0

太乱,不爱看

GrandKai | 园豆:119 (初学一级) | 2015-04-21 13:41
0

虽然没看懂,但看起来很厉害的样子。

519740105 | 园豆:5810 (大侠五级) | 2015-04-21 18:06
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册