Home > Blockchain >  Beautifulsoup remove bracket from output
Beautifulsoup remove bracket from output

Time:01-15

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?

CodePudding user response:

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

CodePudding user response:

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
  • Related