python - BeautifulSoup append包含尖括号会被转换成实体
伊谢尔伦
伊谢尔伦 2017-04-17 14:24:45
0
2
727
from bs4 import BeautifulSoup
    html="<html><body></body></html>"
    soup = BeautifulSoup(html)
    soup.body.append("<test")
    print soup
    "


   输出结果:
"<html><body>&lt;test</body></html>

怎样才能使尖括号不被转换成html实体呢?
如:
<html><body><test</body></html>

伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

reply all(2)
Ty80

http://www.crummy.com/software/BeautifulSoup/bs4/doc/index.zh.html#beautifulsoup-new-string-new-tag

If you want to add a tag, please use new_tag()
It is not a good practice to write a tag directly in append()

Also, angle brackets will be escaped in web pages, otherwise it may cause label exceptions or something

黄舟

The author checked whether it has something to do with the python version, bs version or file encoding. I tested it locally and there was no problem, as shown in the picture

To add: the native python is 2.7.5, the bs version is beautifulsoup4-4.3.2, and the encoding is utf8 without BOM

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template