Python Forum
Preserving anchor tags in BeautifulSoup
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Preserving anchor tags in BeautifulSoup
#1
Hi Guys,

After testing my code i found out the BeautifulSoup strips html tags when using: get_text()

i'm getting data from an .xml file:

xml_content_body = soup.find('taskBody')
This field contains text with anchor text in it, like:

word word word <a href="https://www.thesite.com/">work</a> word etc
Is there a way to keep the html tags instead of stripping them with get_text()?

# beautifulsoup setup
soup = BeautifulSoup(projects.text, 'xml')

# xml values
xml_content_body = soup.find('taskBody')
I cannot see a way to do this, any help would be appreciated guys!

regards

Graham
Reply


Messages In This Thread
Preserving anchor tags in BeautifulSoup - by graham23s - May-18-2019, 07:54 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,660 Oct-27-2022, 08:58 AM
Last Post: wavic
  Loop through tags inside tags in Selenium/Python xpack24 1 5,704 Oct-23-2019, 10:15 AM
Last Post: Larz60+
  remove tags from BeautifulSoup result moski 1 4,715 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