how do i convert base64 string to images from whatsapp using python?

As the comment said, you forgot to remove “data:image/jpeg;base64,” in the code.

If your python version is greater than 3.4, you can do this:

from urllib.request import urlopen

getList = m.find_element_by_class_name("_2kLly").find_element_by_class_name("_2n28r").get_attribute("style").split('"')[1]
# now getList is "data:image/jpeg;base64,/9j/4AAQ..."

with urlopen(getList) as response, open('image.png', 'wb') as f:
    f.write(response.read())

see How to parse data-uri in python?

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top