Handling an image download popup
Question: I'm trying to download an image using Python's Mechanize, and that's an easy
thing to do with urlretrieve, however this image's 'src' attribute holds a url
which initiates a download popup. There doesn't seem to be a url that points
to the image.

I'm using Python Mechanize, but my research tells me that there's no way to
handle the pop up in Mechanize, and I would have to use something like
Selenium. Is this the case?


Answer: Yes Selenium seems to be the case for this. The following code shows how to
deal with pop-up's.

    
    
    from selenium import webdriver
    from selenium.webdriver.common.alert import Alert
    
    driver = webdriver.Firefox()
    driver.get(url)
    
    try:
        alert = self.driver.switch_to_alert()
        # do something with alert, like download the content
        alert.dismiss()
     except:
        pass
    

