Last active
October 23, 2021 15:11
-
-
Save pedrominicz/7129daedbcfa0daed9fc3d266690070a to your computer and use it in GitHub Desktop.
Remove a specific tag from an HTML file.
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
#!/usr/bin/env python3 | |
import bs4 | |
import sys | |
if len(sys.argv) != 3: | |
print(f'usage: {sys.argv[0]} <tag> <file>') | |
sys.exit(1) | |
with open(sys.argv[2], 'r+') as f: | |
soup = bs4.BeautifulSoup(f, 'html.parser') | |
for tag in soup.select(sys.argv[1]): | |
tag.decompose() | |
f.seek(0) | |
f.write(str(soup)) | |
f.truncate() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment