This follows similar logic to BeautifulSoup where we attempt different character encodings until we find one which works.