我正在尝试使用 beautifulsoup 来解析 html,但是每当我点击带有内联脚本标签的页面时,beautifulsoup 都会对内容进行编码,但最终不会将其解码。
这是我使用的代码:
from bs4 import BeautifulSoup
if __name__ == '__main__':
htmlData = '<html> <head> <script type="text/javascript"> console.log("< < not able to write these & also these >> "); </script> </head> <body> <div> start of div </div> </body> </html>'
soup = BeautifulSoup(htmlData)
#... using BeautifulSoup ...
print(soup.prettify() )
我想要这个输出:
<html>
<head>
<script type="text/javascript">
console.log("< < not able to write these & also these >> ");
</script>
</head>
<body>
<div>
start of div
</div>
</body>
</html>
但我得到这个输出:
<html>
<head>
<script type="text/javascript">
console.log("< < not able to write these & also these >> ");
</script>
</head>
<body>
<div>
start of div
</div>
</body>
</html>