Search code examples
pythonpython-2.7seleniumweb-scrapinggetattribute

I need to download images referenced in the href attribute of anchors using Python Selenium


Retrieved links should be obtained in a sequential fashion in order to allow further processing. This is what I've tryied til now:

lay = driver.find_element_by_xpath('//*[@id="app"]/div/div[4]/div[2]/div/div[1]/div/div')
fig = lay.find_elements_by_class_name('_2Mc8_')

for link in fig:
    href = link.get_attribute("href")
    print href
    for ab in href:   
        ab = driver.get(href)
        dwn = driver.find_element_by_xpath('//*[@id="app"]/div/div[3]/div/div[1]/div[1]/header/div[2]/div[3]/a/span')
        dwn.click()
        time.sleep(2)


Solution

  • lay = driver.find_element_by_xpath('//')
    fig = lay.find_elements_by_class_name('_2Mc8_')
    
    for link in fig:
        href = link.get_attribute("href")
        print href
        for ab in href:   
            driver.get(ab)
            dwn = driver.find_element_by_xpath('//')
            dwn.click()
            time.sleep(2)