Created
March 13, 2011 13:08
-
-
Save msalvadores/868074 to your computer and use it in GitHub Desktop.
How to change tag name with BeautifulSoup.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
author: Manuel Salvadores ([email protected]) | |
Code sample in answer from Stack Overflow: | |
http://stackoverflow.com/questions/5289189/how-to-change-tag-name-with-beautifulsoup/5289523#5289523 | |
""" | |
import BeautifulSoup | |
if __name__ == "__main__": | |
data = """ | |
<html> | |
<h2 class="someclass">some title</h2> | |
<ul> | |
<li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</li> | |
<li>Aliquam tincidunt mauris eu risus.</li> | |
<li>Vestibulum auctor dapibus neque.</li> | |
</ul> | |
</html> | |
""" | |
soup = BeautifulSoup.BeautifulSoup(data) | |
h2 = soup.find('h2') | |
h2.name = 'h1' | |
print soup |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
to change them all ...