1

I trying get image from canvas from this website - "https://www.mercari.com/us/item/m84293492444/?ref=category_detail" using python.

But after that i run script and get this error.

'selenium.common.exceptions.WebDriverException: Message: : Failed to execute 'toDataURL' on 'HTMLCanvasElement': Tainted canvases may not be exported.'

My code:

from selenium import webdriver import base64 import time

driver = webdriver.Chrome()

driver.get('https://www.mercari.com/us/item/m84293492444/?ref=category_detail')

time.sleep(2)


big_image = driver.find_elements_by_xpath('/html/body/div[3]/div[1]/div[4]/div[2]/div[1]/div[1]/div[2]/div/div[2]/button/div/img')
big_image[0].click()

time.sleep(3)

canvas = driver.find_elements_by_xpath('/html/body/div[8]/div/div[2]/div[1]/div[1]/div[2]/canvas')
c = canvas[0]
print(c)
try:
    canvas_base64 = driver.execute_script("return arguments[0].toDataURL('image/png').substring(21);", c)
    
    canvas_png = base64.b64decode(canvas_base64)
    
    with open(r'canvas_png', 'wb') as f:
        f.write(canvas_png)
except Exception as e:
    raise e
finally:
    driver.quit()

This solution are working - How to save a canvas as PNG in Selenium?, but not in my case. So, how i can get image from this website? Javascript don't work, or i do something wrong. So, what i must do that get image?

0 Answers0