python 字符串匹配问题
澳门银河官网
澳门银河官网
当前位置 : 澳门银河官网 > 澳门银河官网

python 字符串匹配问题

想匹配html = <div class="back fl"><a href="javascript:void0;" 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:void0;" 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:void0;" onclick="_gaq.push[_trackEvent,function, onclick, blog_articles_shangyipian];location.href=.+?;">
re.findallpattern_l,html

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

 soup = BeautifulSouphtml, "lxml"
        printsoup.find_allonclick="_gaq.push[_trackEvent,function, onclick, blog_articles_shangyipian];location.href=/u012582664/article/details/.+?;"
        

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

前面那一大堆东西其实用不着匹配。

匹配这些就够了:

re.findallr"location.href=/u012582664/article/details/\d+",html

括号转义下试试?小括号和中括号在正则里有特殊意义

栏目列表

广告位

澳门银河官网