Beautifulsoup remove bracket from output

Question:

I am trying to get html from a web page:

try:
    description=hun.select('#description > div.tab-pane-body > div > div > div > table')
except:
    description=None

result = {"description":str(description)}

data.append(result)

print(json2xml.Json2xml(data, wrapper="all", pretty=True, attr_type=False).to_xml())

This works fine, but I have "[<span>Test</span>]" brackets in the output. How can I avoid these brackets from the output?

Asked By: Adrian

||

Answers:

Could be linked to "description" being a list. Otherwise you could use .text on the object to return the value as string.

try:
    description = hun.select('#description > div.tab-pane-body > div > div > div > table')[0].text
except:
    description = None
Answered By: Kasperds

This will get you the element without bracket:

try:
    description = hun.select('#description > div.tab-pane-body > div > div > div > table')[-1]
except:
    description = None
Answered By: Talha Tayyab
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.