Python Forum
Preserving anchor tags in BeautifulSoup
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Preserving anchor tags in BeautifulSoup
#5
Quote:print("RAW: This is an <a href=\"https://www.thesite.com/\">test</a> string.")
This is just a string and not valid html or xml.
Then can regex be a better tool.
>>> import re
>>> 
>>> s = "RAW: This is an <a href=\"https://www.thesite.com/\">test</a> string."
>>> re.sub(r'<.*>', '', s)
'RAW: This is an  string.'
Reply


Messages In This Thread
RE: Preserving anchor tags in BeautifulSoup - by snippsat - May-18-2019, 09:58 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  BeautifulSoup - I can't translate html tags that contain <a href=..</a> OR <em></em> Melcu54 10 1,736 Oct-27-2022, 08:58 AM
Last Post: wavic
  Loop through tags inside tags in Selenium/Python xpack24 1 5,735 Oct-23-2019, 10:15 AM
Last Post: Larz60+
  remove tags from BeautifulSoup result moski 1 4,727 Jun-05-2019, 01:47 PM
Last Post: heiner55

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020