0

Python wont decode unicode when the variable is not hardcoded

I scraped this string from the web

VLANiOsFxjklHNP3iuIkjdPNjvqEQCIWE05ZxyDGkM6b7YiPwMkdE97lfMPIgj5rhuCN9qzDM\u002fb0nUTbj\u002fVEs

I want to turn it to

VLANiOsFxjklHNP3iuIkjdPNjvqEQCIWE05ZxyDGkM6b7YiPwMkdE97lfMPIgj5rhuCN9qzDM/b0nUTbj/VEs

If I hard code the in python 3.6, it will print as the second item. However, if I scrape it from the web and print, it will continue to print as the first value. I don't get it.

source = """"isCustomPerf":1,"uiflvr":1001,"btReportingOn":0,"cxhReporting":1,"uaid":"b32f5a2af44a417096c4d182ada83916","uhf":{"currentMenuItemId":""},"apiCanary":"M10GhqLS3Yoy\u002f4ewFEC5aFANm7Eq\u002b6morkRlZjxyQvyboEYn\u002brvaY5rcKI9PIsbJXHNo8LMusrQrL51bftV7JUjcXm0\u002bgTYBfKZ5ttz\u002ftgfjPvJPe\u002fxuwpvkEgt7uiFBtzy0NA1H8MXFjBEKdBixYFrZksDUelo3fOu0QlNKgxR52oI1gJgY\u002biC37jPB3ZA7oi\u002bjv6UV2PYa3ogCP\u002f13QasikHXgL7ea7IxlS24a\u002fP\u002bdvxo6yheKlI5iGz9GfUAw\u003a2\u003a3c","ip":"91.207.175.197","cid":"UnAuth","displayMemberName":"UnAuth","mkt":"en-US","email":"UnAuth","mktLocale":"en-US"};window.$Do && window.$Do.register("$Config", 0, true);"""


print(type(source))
unicode_api_canary = str(source.split('"apiCanary":"')[1].split('","ip"')[0])
print(type(unicode_api_canary))


print(unicode_api_canary)

The issue is that if I hardcode source, it works, but I'm scraping the value from the web as a string... and it wont evaluate the unicode in that string.

CENTURION
  • 355
  • 3
  • 11

0 Answers0