python - Replacing Selections of HTML via the Command-Line -
edit: know how this. i'm not looking solution, i'm looking process or existing program recommendation before take time write myself in scripting language.
i have html files in various directories have similar structure:
<html> <head>...</head> <body> <nav>...</nav> <section>...</section> </body> </html>
i'd programmatically replace html sections other sections (e.g. replace <nav>
block different nav
block [specified in file of choosing]) files specify.
i think ideal solution sort of tool using lxml
or similar in python, if there easy way *nixy tools, or existing program this, i'd happy instead of putting script.
you might able use beautifulsoup python so.
import beautifulsoup soup = beautifulsoup.beautifulsoup(htmldata) nav = soup.find("nav") nav.name = "new name"
for example:
import beautifulsoup html_data = "<nav>some text</nav>" soup = beautifulsoup.beautifulsoup(html_data) nav = soup.find("nav") nav.name = "nav2"
will change: <nav></nav>
<nav2></nav2>