Make bs4 only replace the tag name instead of name and contents

This commit is contained in:
Agatha Rose 2021-02-18 18:01:43 +02:00
parent d07d49d42e
commit 27f61c4374
No known key found for this signature in database
GPG Key ID: 2DB18BA2E0A80BC3
1 changed files with 2 additions and 2 deletions

View File

@ -68,10 +68,10 @@ def extract_toot(toot):
toot = html.unescape(toot) # convert HTML escape codes to text toot = html.unescape(toot) # convert HTML escape codes to text
soup = BeautifulSoup(toot, "html.parser") soup = BeautifulSoup(toot, "html.parser")
for lb in soup.select("br"): # replace <br> with linebreak for lb in soup.select("br"): # replace <br> with linebreak
lb.replace_with("\n") lb.name = "\n"
for p in soup.select("p"): # ditto for <p> for p in soup.select("p"): # ditto for <p>
p.replace_with("\n") p.name = "\n"
for ht in soup.select("a.hashtag"): # convert hashtags from links to text for ht in soup.select("a.hashtag"): # convert hashtags from links to text
ht.unwrap() ht.unwrap()