Save All Image Files from a Website

how to save all images from a website in python

Hello I did this I create the Xpath for every image and then get the source code

import requests
import selenium
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import urllib.request

PATH=r'C:\Program Files (x86)\chromedriver.exe'
driver= webdriver.Chrome(PATH)
page=driver.get(r'https://511ny.org/cctv')

try:
main = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.XPATH, '//*[@id="cctvTable"]/tbody'))
) # I used XPATH of the table
print (main.text)
except:
driver.quit()

items=main.find_elements_by_tag_name('tr') # I use tr tag

for item in items:
# print(item.text)
#Get id
identificador=item.get_attribute('data-id')

#Creating xpath and getting the image
xpath='//*[@id="{}img"]'.format(identificador)
imagen=item.find_elements_by_xpath(xpath)[0]
src=imagen.get_attribute('src')
urllib.request.urlretrieve(src,'{}.jpg'.format(identificador))

Thank you

Download all images from a single directory of a website

Have a look at HTTrack software. It can download whole sites. Give website address site.com/images/ and it will download everything in this directory. (if the directory access is not restricted by owner)

Save all image files from a website

URL = '[my blog url]'

require 'nokogiri' # gem install nokogiri
require 'open-uri' # already part of your ruby install

Nokogiri::HTML(open(URL)).xpath("//img/@src").each do |src|
uri = URI.join( URL, src ).to_s # make absolute uri
File.open(File.basename(uri),'wb'){ |f| f.write(open(uri).read) }
end

Using the code to convert to absolute paths from here: How can I get the absolute URL when extracting links using Nokogiri?

How do I use Wget to download all images into a single folder, from a URL?

Try this:

wget -nd -r -P /save/location -A jpeg,jpg,bmp,gif,png http://www.somedomain.com

Here is some more information:

-nd prevents the creation of a directory hierarchy (i.e. no directories).

-r enables recursive retrieval. See Recursive Download for more information.

-P sets the directory prefix where all files and directories are saved to.

-A sets a whitelist for retrieving only certain file types. Strings and patterns are accepted, and both can be used in a comma separated list (as seen above). See Types of Files for more information.

Trying to download all of the images on the website using javascript

You’re using an entire array as the src attribute. try:

var images = document.getElementsByTagName('img');
var srcList = [];
var i = 0;

setInterval(function(){
if(images.length > i){
srcList.push(images[i].src);
var link = document.createElement("a");
link.id=i;
link.download = images[i].src;
link.href = images[i].src;
link.click();
i++;
}
},1500);

Getting all images from a webpage and save the to disk programmatically (NodeJS & Javascript)

This feels like you should use a crawler. The following code should work (using the npm module crawler):

const Crawler = require("crawler")

const c = new Crawler({
callback: function(error, res, done) {
if (error) {
console.log({error})
} else {
const images = res.$('.person div img')
images.each(index => {
// here you can save the file or save them in an array to download them later
console.log({
src: images[index].attribs.src,
alt: images[index].attribs.alt,
})
})
}
}
})

c.queue('https://www.yoursite.com')

How to download ALL the pictures of a webpage and save them in their original names?

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')
for image in images:
src = image.get_attribute("src")
if src:
urllib.urlretrieve(src)

Save all image files from a website

URL = '[my blog url]'

require 'nokogiri' # gem install nokogiri
require 'open-uri' # already part of your ruby install

Nokogiri::HTML(open(URL)).xpath("//img/@src").each do |src|
uri = URI.join( URL, src ).to_s # make absolute uri
File.open(File.basename(uri),'wb'){ |f| f.write(open(uri).read) }
end

Using the code to convert to absolute paths from here: How can I get the absolute URL when extracting links using Nokogiri?



Related Topics



Leave a reply



Submit