>  Q&A  >  본문

python 字符串匹配问题

想匹配html = <p 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></p><p 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></p>中的‘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/(.+?)';"))
        

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

ringa_leeringa_lee2719일 전456

모든 응답(2)나는 대답할 것이다

  • PHP中文网

    PHP中文网2017-04-18 10:34:04

    사실 눈앞에 있는 것들은 굳이 맞출 필요는 없습니다.

    다음과 일치하면 충분합니다.

    으아아아

    회신하다
    0
  • 迷茫

    迷茫2017-04-18 10:34:04

    괄호를 벗어나시겠습니까? 괄호와 대괄호는 정규 표현식에서 특별한 의미를 갖습니다

    회신하다
    0
  • 취소회신하다