I am using python + BeautifulSoup to parse an HTML document.
Now I need to replace all <h2 class="someclass"> elements in an HTML document, with <h1 class="someclass">.
How can I change the tag name, without changing anything else in the document?
I don’t know how you’re accessing
tagbut the following works for me:Output of
print soupcommand is:As you can see,
h2becameh1. And nothing else in the document changed. I am using Python 2.6 and BeautifulSoup 3.2.0.If you have more than one
h2and you want to change them all, you could simple do: