I am getting a str from BeautifulSoup that contains escaped characters using \xXX
notation that needs to be decoded into a regular str.
Example:
next_url = r'\x26hl\x3den'
After conversion, I want:
next_url = '&hl=en'
It appeared simple at first, but I have not been able to find a solution after an hour of search. What is a good way to do it?
EDIT: adding some code in response to the comments. It is really simple.
session = requests.Session()
r = session.get(url)
soup = BeautifulSoup(r.text, 'html.parser')
next_url = soup.find(class_='XXXX')['onclick'].split('=', 1)[1][1:-1] # handles: onclick="window.location='http:domain.com/path'"
next_url
needs to be decoded.