How to convert replacement characters into UTF-8 characters with Python after grabbing text using Selenium

236 Views Asked by At

I grabbed text from a specific classes child nodes using this subroutine

elements = WebDriverWait(self.driver, 10).until(EC.presence_of_all_elements_located((By.CLASS_NAME, "gamesRow")))
for a in elements:
    self.formatBets(a.text)

and the converted string after applying the .text attribute looks something like this:

May 05 1
NASHVILLE PREDATORS
-1�+150
o5�+110
-185
More +
4:08 PM
  2 COLUMBUS BLUE JACKETS
+1�-170
u5�-130
+165

How would I go about converting those replacement characters (�), as they appear in the original HTML.

In the original HTML, the replacement characters are denoted as fractions, specifically 1/2

Sorry if this is a bit confusing, I'm new to webscraping and HTML so if this needs more clarification please let me know and I'll edit the question!

1

There are 1 best solutions below

1
On

Try this change on your code, just encode the text. Are you using python2 or python3?

self.formatBets(a.text.encode("utf-8"))