Python BeautifulSoup是包含转义字符的HTML转义字符串
我正在从文件中读取字符串:Python BeautifulSoup是包含转义字符的HTML转义字符串,python,escaping,beautifulsoup,html-escape-characters,Python,Escaping,Beautifulsoup,Html Escape Characters,我正在从文件中读取字符串: a = '<script>closedSign: \'<img src="/static/images/drop-down.png" style="margin-top: -3px;" />\'</script>' a='closedSign:\'\' 现在,当我跑的时候 BeautifulSoup(a) <script>closedSign: '<img src="/static/images/d
a = '<script>closedSign: \'<img src="/static/images/drop-down.png" style="margin-top: -3px;" />\'</script>'
a='closedSign:\'\'
现在,当我跑的时候
BeautifulSoup(a)
<script>closedSign: '<img src="/static/images/drop-down.png" style="margin-top: -3px;" />'</script>
BeautifulSoup(a)
closedSign:'img src=“/static/images/drop-down.png”style=“margin top:-3px;”/'
因此,请查看的“实体转换”部分
使用BeautifulSoup 3.2.0而不是3.2.1来解决此问题。避免什么?你想获得什么?只是编辑了问题以便更好地解释它。另外,刚刚注意到这个问题只发生在BeautifulSoup3.2.1上,而不是在3.2.0上。听起来您遇到了这个问题:Paulo,convertEntities=BeautifulSoup.HTML\u ENTITIES在已经被HTML转义的字符串上工作。示例:从解析返回![]()
bs4
用户:convertEntities
在bs4中不再存在。我也解决了这个问题。非常感谢您的解决方案和-1,感谢BeautifulSoup在一次小的更新后破坏了这样一个东西。
soup = BeautifulSoup(html, convertEntities=BeautifulSoup.HTML_ENTITIES)