来源:https://stackoverflow.com/questions/9766966/how-to-set-value-in-with-beautiful-soup-in-some-html-element-if-i-know-id-of-tha
代码
from bs4 import BeautifulSoup
soup = None
with open('abc.html', 'rb') as f:
soup = BeautifulSoup(f.read(), "html.parser" )
t = soup.find("title")
t.string = 'Hello World'
html = soup.prettify() # 获取格式化后的 html 文本
安装 BeautifulSoup
pip install BeautifulSoup4