我试图使用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() )
我想要这个输出:
^{pr2}$但我得到的输出是:
<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>
您可能想试试lxml:
收益率
^{pr2}$你可以这样做:
相关问题 更多 >
编程相关推荐