嘿,伙计们,我想做的是用漂亮的汤把一个html页面的内容插入到另一个页面中。
with open("testpage.html") as fp:
mainSoup = BeautifulSoup(fp)
with open("navbarContent.html") as fp:
extraSoup = BeautifulSoup(fp)
for elm in mainSoup.find_all('nav', {"id":"sidebar"}):
elm.string= str(extraSoup)
所以我希望在标记的testpage.html中插入navbarContent.html的html内容。有什么想法吗?
发布于 2020-04-09 18:22:38
您可以将html代码添加到三引号中,如下所示:
htmlCode = ´´´
<html>
</html>
´´´
然后,将navbarContent的内容添加到其中,然后可以使用write()
将整个内容再次写入html文件。
但首先你必须对文件执行open()
,然后你必须对文件执行close()
操作。我希望你知道这是怎么回事。
https://stackoverflow.com/questions/61118882
复制相似问题