请问这里的数据如何用Python的正则表达式匹配出来?(或者其他更简便方法?)

2025-02-25 05:35:40
推荐回答(2个)
回答1:

# -*- coding:utf-8 -*-
import re
s=u'[{"timestamp":1462590135,"rawXML":"<\/id><\/username><\/createTime>0<\/contentDescShowType>4<\/contentDescScene><\/private><\/contentDesc><\/contentattr><\/sourceUserName><\/sourceNickName><\/statisticsData><\/location><\/contentStyle><![CDATA[婚姻中遇到真爱,要不要离婚?]]><\/title><description><![CDATA[婚姻中遇到真爱应该离婚吗?\n真的有灵魂伴侣吗?\n如何判断一个人适不适合成为自己的伴侣?]]><\/description><contentUrl><!'<br><br>m=re.compile('<username>(.*)<\\\/username>')<br>print re.search(m, s).groups()[0]<br><br>输出>>><br><![CDATA[xxxxxx123]]></pre> <p>注意:\及/为正则表达式中特殊符号,需要转义才可用。</p></p> </div> </div> <div class="clear"></div> </div> <div class="wdhdnr"> <div class="huidanrtop"> <div class="wdhuidaxinx"> <div class="wdhuidaxm">回答2:</div> </div> </div> <div class="clear"></div> <div class="wdhuidanrmid"> <div class="zuijiacont"> <p>目测需要json和xml模块, json把数据转成json格式,然后从其中提取rawXML, 这段用xml模块解析</p> </div> </div> <div class="clear"></div> </div> </div> </div> <div class="wendaright"> <div class="wdluluerwema"> <div class="wdxgwttop">相关问答</div> <div class="wdxgwtnr"> </div> <div class="clear"></div> </div> <!-- 其他随机问答['id'=>alphaID($like['zid'])] --> <div class="wdluluerwema"> <div class="wdxgwttop">最新问答</div> <div class="wdxgwtnr"> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://13l.net/index.php/l/690215508505913084.html">我的电脑网络连接找不到,无法启动network connections服务,启动时提示错误1068</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://13l.net/index.php/l/2122680232715296387.html">男方起诉离婚,女方可以得到相应的补偿吗</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://13l.net/index.php/l/1178502144755353819.html">如果发生了著作权纠纷,应该到哪里寻求解决?</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://13l.net/index.php/l/2139145509901324148.html">吃哪些食物增长雌激素</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://13l.net/index.php/l/1831509259266242820.html">完美国际2血池限时95级怪,是用来刷12倍的吗,经验多不多?本人98级!</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://13l.net/index.php/l/989394882425129539.html">只狼分辨率超屏</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://13l.net/index.php/l/527629852.html">一块地总会有一粒种子适合它,也总会有属于它的一片收成和是金子总会发光 意义相同吗?</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://13l.net/index.php/l/2205479601273520428.html">拔罐对22岁的女性有哪些好处和坏处</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://13l.net/index.php/l/558170305938030492.html">住房公积金纠纷属于劳动争议范围吗</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://13l.net/index.php/l/1177700643015096259.html">2016年湖北省高考考了632能进什么大学 理科</a></div> </div> </div> </div> </div> <div class="clear"></div> <div class="footer"> <!-- 移动底部导航 --> <div class="fanhuitop"><a href="#top" ref="nofollow"><img src="https://13l.net/static/old/img/fhtop.png" alt="返回顶部" title="返回顶部"></a></div> <div class="dibu"> <div class="dibu"> </div> </div> <div class="banquan"> <p>内容全部来源于网络收集,如有侵权,请联系网站删除:QQ:24596024</p> </div> </div> </div> </div> <script> var _hmt = _hmt || []; (function() { var hm = document.createElement("script"); hm.src = "https://hm.baidu.com/hm.js?de17be6dbd20544dd6483cc235b540f9"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })(); </script> </body> </html>