Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save MhmdRyhn/8da959e8c65d7ac20523c95cec022245 to your computer and use it in GitHub Desktop.
Save MhmdRyhn/8da959e8c65d7ac20523c95cec022245 to your computer and use it in GitHub Desktop.
# Taken from: https://stackoverflow.com/a/49207730/5600965
# This requires BeautifulSoup
# cfemail = element.__dict__['attrs'].get('data-cfemail')
def get_protected_email(cfemail):
"""
** Retrieve e-mail from the protected state
** Arguments:
- cfemail: value of `data-cfemail` attribute
** Returns:
- The e-mail in plain text (as string)
"""
if not cfemail:
return ''
encoded_bytes = bytes.fromhex(cfemail)
email = bytes(byte ^ encoded_bytes[0] for byte in encoded_bytes[1:]).decode('utf8')
return email
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment