Jun-03-2020, 09:23 PM
(Jun-03-2020, 01:35 PM)snippsat Wrote: There is nou''
in Python 3,so follow advice over.
# Python 3.8 >>> s = u'\xbd' >>> s '½' # Can remove <u> make no difference >>> s = '\xbd' >>> s '½'# Python 2.7 >>> s = u'\xbd' >>> s u'\xbd' >>> s.encode() Traceback (most recent call last): File "<interactive input>", line 1, in <module> UnicodeEncodeError: 'ascii' codec can't encode character u'\xbd' in position 0: ordinal not in range(128) # Try the obvious one first >>> s.encode('utf-8') '\xc2\xbd' >>> print(s.encode('utf-8')) ½ # Make a guess >>> print(s.encode('latin-1')) ½On of the biggest changes moving to Python 3 was to make Unicode better
Thanks for your help.
But I don't get where this will fit in my code?
Specifically what I am looking at is this:
<span class="rp-horseTable__pos__length">
<span>2½</span>
<span>[5½]</span>
</span>
I want what's in the square brackets, within the second nested span.
If I grab the whole lot by referencing the span class, I then run into the problem above when using re.search() on the square bracket. It's caused (apparently) by the fraction in the first span.
Can I get at the second span directly?
thanks