BeautifulSoup 4 がインライン JavaScript の一部の文字をエスケープしているように見えることを発見しました。
>>> print s
<DOCTYPE html>
<html>
<body>
<h1>Test page</h1>
<script type="text/javascript">
//<!--
if (4 > 3 && 3 < 4) {
console.log("js working");
}
//-->
</script>
</body>
</html>
>>> import bs4
>>> soup = bs4.BeautifulSoup(s, 'html5lib')
>>> print soup
<html><head></head><body><doctype html="">
<h1>Test page</h1>
<script type="text/javascript">
//<!--
if (4 > 3 && 3 < 4) {
console.log("js working");
}
//-->
</script>
</doctype></body></html>
>>> print soup.prettify()
<html>
<head>
</head>
<body>
<doctype html="">
<h1>
Test page
</h1>
<script type="text/javascript">
//<!--
if (4 > 3 && 3 < 4) {
console.log("js working");
}
//-->
</script>
</doctype>
</body>
</html>
上記で失われた場合、重要な問題は次のとおりです。
if (4 > 3 && 3 < 4)
に変換されます:
if (4 > 3 && 3 < 4)
これは特にうまく機能しません...
メソッドに含まれているフォーマッターを試しましたが、prettify()
成功しませんでした。
では、JavaScript のエスケープを停止する方法はありますか? または、出力する前にエスケープを解除する方法は?