码迷,mamicode.com
首页 > 编程语言 > 详细

python 字符串匹配问题

时间:2017-06-11 14:54:29      阅读:131      评论:0      收藏:0      [点我收藏+]

标签:html   title   asc   cli   dpm   答案   str   print   www   

想匹配html = <div class="back fl"><a href="javascript:void(0);" onclick="_gaq.push([‘_trackEvent‘,‘function‘, ‘onclick‘, ‘blog_articles_shangyipian‘]);location.href=‘/u012582664/article/details/56845037‘;"><span><i class="fa fa-arrow-left"></i></span><em>安装最新版python</em></a></div><div class="forward fr"><a href="javascript:void(0);" onclick="_gaq.push([‘_trackEvent‘,‘function‘, ‘onclick‘, ‘blog_articles_xiayipian‘]);location.href=‘/u012582664/article/details/59120585‘;"><em>各种数据库的注释</em><span><i class="fa fa-arrow-right"></i></span></a></div>中的‘56845037’和‘59120585’,尝试用正则:

pattern_l = r‘‘‘<a href="javascript:void(0);" onclick="_gaq.push([‘_trackEvent‘,‘function‘, ‘onclick‘, ‘blog_articles_shangyipian‘]);location.href=‘(.+?)‘;">‘‘‘
re.findall(pattern_l,html)

结果不成功。返回为空,有用:

 soup = BeautifulSoup(html, "lxml")
        print(soup.find_all(onclick="_gaq.push([‘_trackEvent‘,‘function‘, ‘onclick‘, ‘blog_articles_shangyipian‘]);location.href=‘/u012582664/article/details/(.+?)‘;"))
        

还是返回空,请教各位怎么写才行,是哪里出了问题


python 字符串匹配问题 >> python

这个答案描述的挺清楚的:
http://www.goodpm.net/postreply/python/1010000008985846/python字符串匹配问题.html

python 字符串匹配问题

标签:html   title   asc   cli   dpm   答案   str   print   www   

原文地址:http://www.cnblogs.com/scrumme/p/6985087.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!