Skip to content Skip to sidebar Skip to footer

How To Download All The Pictures Of A Webpage And Save Them In Their Original Names?

I coded a small Python script to download a picture from a website using selenium: from selenium import webdriver import urllib.request class FirefoxTest: def firefoxTest(self)

Solution 1:

You need to switch to find_elements_by_tag_name. For downloading files, I'd use urllib.urlretrieve() - it would extract the filename from the url for you:

images = self.driver.find_elements_by_tag_name('img')
forimagein images:
    src = image.get_attribute("src")
    if src:
        urllib.urlretrieve(src)

Solution 2:

You can use Ruby gems nokogiri to open the web page and download the images using their xpath.


require'open-uri'require'nokogiri'

f = open('sample.flv')
begin
    http.request_get('/sample.flv') do |resp|
        resp.read_body do |segment|
            f.write(segment)
        endend
ensure
    f.close()
end

Post a Comment for "How To Download All The Pictures Of A Webpage And Save Them In Their Original Names?"