答案很簡單,可能會遺漏許多細微差別。 如何,這應該給你一個理念,如何進行它,通常改進它。 我相信這可以能會有所改進,但你應該能夠通過文檔的幫助快速完成這些操作。from bs4 import BeautifulSoup
doc = ['
'
Page title','
This is paragraph one.',
'
This is paragraph two.',
'']
soup = BeautifulSoup(''.join(doc))
for tag in soup.findAll('script'):
# Use extract to remove the tag
tag.extract()
# use simple insert
soup.body.insert(len(soup.body.contents), tag)
print soup.prettify()
輸出:
Page title
This is paragraph
one
.
This is paragraph
two
.
document.write("Hello World!")