あなたはBeautifulSoupを使用することができます。
from bs4 import BeautifulSoup
html = '''
<html><body>
<h6>variable 1</h6>
<h8>variable 3</h8>
</body></html>
'''
soup = BeautifulSoup(html, 'html.parser')
h6 = soup.find_all('h6') # all elements that match your filters
h8 = soup.find('h8') # return one element
# replace all h6 tags string it with the the string of your choice:
for tag in h6:
tag.string.replace_with('new variable value')
h8.string.replace_with('new text')
print str(soup)
#Output
<html><body>
<h6>new variable value</h6>
<h8>new text</h8>
</body></html>py
がbeautifulsoupに見て、あなたは、HTMLを読み込むbeautifulsoupでそれを編集し、再度、ファイルを保存することができます。 http://stackoverflow.com/questions/35355225/edit-and-create-html-file-using-python – altoids