2

In my attribute table there's a lot of html formatted text. Is there a quick way to convert that html to 'normal' UTF-8 text other than using replace() for every html special character?

replace('<p>W&uuml;rstelstand</p>','&uuml','ü')

UPDATE: I tried using BeutifulSoup in the function editor without success:

from bs4 import BeautifulSoup

@qgsfunction(args='auto', group='Python')
def html2text(text,feature, parent):
    soup = BeautifulSoup(text)
    return soup.string

However it works when done as standalone script but a custom function in the field calculator would be nice.

3

1 Answer 1

2

After fiddeling around with the function editor I found an adequate solution:

from bs4 import BeautifulSoup

@qgsfunction(args='auto', group='Python')
def html2text(text,feature, parent):
    soup = BeautifulSoup(text)
    return str(soup.string)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.