首頁  >  問答  >  主體

python怎么用正则怎么获取标题

<h3 class="title h1 js-title"> 
<a href="/wenda/2084" target="2084" data-main-tab="/wenda/2084" data-new-tab="php.cn/python-tutorials-351098.html"> $300 Off Phantom 3 Standard </a> 
</h3>
大家讲道理大家讲道理2897 天前846

全部回覆(3)我來回復

  • 阿神

    阿神2017-02-08 17:32:53

    反向思维, 从标签中找到文本很麻烦, 所以我们干脆就把别的标签都干掉

    import re
    html = u'<h3 class="title h1 js-title"> <a href="/wenda/2084" target="2084" data-main-tab="/wenda/2084" data-new-tab="php.cn/python-tutorials-351098.html"> $300 Off Phantom 3 Standard </a> </h3>'title = re.sub(ur'<.+?>', '', html).strip()print title # $300 Off Phantom 3 Standard


    回覆
    0
  • 取消回覆