I am using the python module HTMLParser.py
I am able to parse HTML correctly but is there an option to change a HTML elements data(innerText)?
Do you know how I can 开发者_如何学Pythondo this with the module HTMLParser?
No, the HTMLParser does just that: it parses through your HTML.
You're probably looking for Beautiful Soup. It'll create a ParseTree--a Pythonic tree of objects representing the HTML elements of your document. Then, you can search up the object (element) you want, assign it a new value, and voila!
Stolen shamelessly from the documentation:
from BeautifulSoup import BeautifulSoup
soup = BeautifulSoup("<b>Argh!</b>")
soup.find(text="Argh!").replaceWith("Hooray!")
print soup
# <b>Hooray!</b>
精彩评论