Python Forum
[SOLVED] [BeautifulSoup] Why does it turn inserted string's brackets into </>?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[SOLVED] [BeautifulSoup] Why does it turn inserted string's brackets into </>?
#1
Hello,

One more before I go to bed…

No matter what I try, BS turns the brackets of the LS string into "<" and ">" instead of keeping them as is:

from bs4 import BeautifulSoup 

soup = BeautifulSoup(open('input.kml', 'r'), 'xml')

LS = "<Style><LineStyle><color>FF0000FF</color><width>6</width></LineStyle></Style>"

for ls in soup.find_all("LineString"):
	parent = ls.parent

	#BAD parent.insert(0,LS)
	#BAD parent.insert(0,LS.encode(formatter="html"))
	#BAD parent.insert(0,str(LS)) 

print(soup.prettify())
Thank you.

--
Edit: Found a solution

print(soup.prettify(formatter=None))
with open(OUTPUTFILE, "w") as file:
    #file.write(str(soup))
    file.write(soup.prettify(formatter=None))
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  gpiozero button turn off LED that is already on duckredbeard 3 745 Dec-11-2024, 06:23 PM
Last Post: duckredbeard
  [SOLVED] Sub string not found in string ? jehoshua 4 1,337 Dec-03-2024, 09:17 PM
Last Post: jehoshua
Question [SOLVED] How to replace characters in a string? Winfried 2 944 Sep-04-2024, 01:41 PM
Last Post: Winfried
  [SOLVED] [BeautifulSoup] Why are some elements ignored? Winfried 5 1,524 Sep-04-2024, 09:34 AM
Last Post: Winfried
  Exceeding the value - turn on the relay. stsxbel 0 544 May-27-2024, 07:18 PM
Last Post: stsxbel
  [SOLVED] [BeautifulSoup] Why attribute not found? Winfried 0 1,238 Mar-11-2023, 10:00 PM
Last Post: Winfried
  [SOLVED] [Beautifulsoup] Find if element exists, and edit/append? Winfried 2 6,863 Sep-03-2022, 10:14 PM
Last Post: Winfried
  [SOLVED] [BeautifulSoup] Turn select() into comma-separated string? Winfried 0 1,881 Aug-19-2022, 08:07 PM
Last Post: Winfried
  [SOLVED] [BeautifulSoup] How to get this text? Winfried 6 3,068 Aug-17-2022, 03:58 PM
Last Post: Winfried
  Inserting line feeds and comments into a beautifulsoup string arbiel 1 2,090 Jul-20-2022, 09:05 AM
Last Post: arbiel

Forum Jump:

User Panel Messages

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