newlink = link['href']# .. make replacementslink['href'] = newlink # store it back
现在
print(soup.prettify())将显示更改的链接。要将更改保存到文件:
htmlDoc.close()html = soup.prettify("utf-8")with open("output.html", "wb") as file: file.write(html)要保留文档的原始字符编码,可以使用
soup.original_encoding“
utf-8”代替。请参阅编码。



