Filter out HTML tags and resolve entities in python

前端 未结 8 1749
暗喜
暗喜 2020-12-03 00:11

Because regular expressions scare me, I\'m trying to find a way to remove all HTML tags and resolve HTML entities from a string in Python.

相关标签:
8条回答
  • 2020-12-03 00:38

    How about parsing the HTML data and extracting the data with the help of the parser ?

    I'd try something like the author described in chapter 8.3 in the Dive Into Python book

    0 讨论(0)
  • 2020-12-03 00:42

    You might need something more complicated than a regular expression. Web pages often have angle brackets that aren't part of a tag, like this:

     <div>5 < 7</div>
    

    Stripping the tags with regex will return the string "5 " and treat

     < 7</div>
    

    as a single tag and strip it out.

    I suggest looking for already-written code that does this for you. I did a search and found this: http://zesty.ca/python/scrape.html It also can resolve HTML entities.

    0 讨论(0)
提交回复
热议问题