Download Images from Array
up vote
1
down vote
favorite
Background:
I'm new to JS (started learning this week) and I've been playing around with the Chrome Dev Tools and the Console on the following website: https://www.pokemon.com/us/pokedex/
I went into the dev tools element selector and located the with class="results" which is basically all of the pokemon listed.
I edited the tag to include an id (id="poke") so I could play around with it.
The following is my code that outputs an array with all of the links to the pokemon image assets:
function listPokemon()
var pokeAssets = document.getElementById('poke').getElementsByTagName('img');
var i;
for (i = 0; i < pokeAssets.length; i++)
console.log (pokeAssets[i]);
Question:
Is there a way to download all of the image assets from that array without having to do so manually using vanilla javascript?
javascript
|
show 1 more comment
up vote
1
down vote
favorite
Background:
I'm new to JS (started learning this week) and I've been playing around with the Chrome Dev Tools and the Console on the following website: https://www.pokemon.com/us/pokedex/
I went into the dev tools element selector and located the with class="results" which is basically all of the pokemon listed.
I edited the tag to include an id (id="poke") so I could play around with it.
The following is my code that outputs an array with all of the links to the pokemon image assets:
function listPokemon()
var pokeAssets = document.getElementById('poke').getElementsByTagName('img');
var i;
for (i = 0; i < pokeAssets.length; i++)
console.log (pokeAssets[i]);
Question:
Is there a way to download all of the image assets from that array without having to do so manually using vanilla javascript?
javascript
Would you be satisfied with a solution that opens new tabs for each img so you can simply tab through them and press CTRL-S on each?
– connexo
Nov 9 at 21:14
You don't need to manually add an ID to the element. This works as well:document.querySelectorAll('.results')[0].getElementsByTagName('img')
– Will
Nov 9 at 21:17
1
@Will Why would you dodocument.querySelectorAll('.results')[0]
when you can just do the natural thingdocument.querySelector('.results')
?
– connexo
Nov 9 at 21:19
No, you can't. I don't know what is your main purpose. You're trying to learn JS or just want to download those images. If you want to learn, do other things since there still be a lot to learn. If you want to scrape those images, take a look at casperJS.
– vnt
Nov 9 at 21:21
@connexo Indeed. Old habits!
– Will
Nov 9 at 21:25
|
show 1 more comment
up vote
1
down vote
favorite
up vote
1
down vote
favorite
Background:
I'm new to JS (started learning this week) and I've been playing around with the Chrome Dev Tools and the Console on the following website: https://www.pokemon.com/us/pokedex/
I went into the dev tools element selector and located the with class="results" which is basically all of the pokemon listed.
I edited the tag to include an id (id="poke") so I could play around with it.
The following is my code that outputs an array with all of the links to the pokemon image assets:
function listPokemon()
var pokeAssets = document.getElementById('poke').getElementsByTagName('img');
var i;
for (i = 0; i < pokeAssets.length; i++)
console.log (pokeAssets[i]);
Question:
Is there a way to download all of the image assets from that array without having to do so manually using vanilla javascript?
javascript
Background:
I'm new to JS (started learning this week) and I've been playing around with the Chrome Dev Tools and the Console on the following website: https://www.pokemon.com/us/pokedex/
I went into the dev tools element selector and located the with class="results" which is basically all of the pokemon listed.
I edited the tag to include an id (id="poke") so I could play around with it.
The following is my code that outputs an array with all of the links to the pokemon image assets:
function listPokemon()
var pokeAssets = document.getElementById('poke').getElementsByTagName('img');
var i;
for (i = 0; i < pokeAssets.length; i++)
console.log (pokeAssets[i]);
Question:
Is there a way to download all of the image assets from that array without having to do so manually using vanilla javascript?
javascript
javascript
asked Nov 9 at 21:08
Dale
82
82
Would you be satisfied with a solution that opens new tabs for each img so you can simply tab through them and press CTRL-S on each?
– connexo
Nov 9 at 21:14
You don't need to manually add an ID to the element. This works as well:document.querySelectorAll('.results')[0].getElementsByTagName('img')
– Will
Nov 9 at 21:17
1
@Will Why would you dodocument.querySelectorAll('.results')[0]
when you can just do the natural thingdocument.querySelector('.results')
?
– connexo
Nov 9 at 21:19
No, you can't. I don't know what is your main purpose. You're trying to learn JS or just want to download those images. If you want to learn, do other things since there still be a lot to learn. If you want to scrape those images, take a look at casperJS.
– vnt
Nov 9 at 21:21
@connexo Indeed. Old habits!
– Will
Nov 9 at 21:25
|
show 1 more comment
Would you be satisfied with a solution that opens new tabs for each img so you can simply tab through them and press CTRL-S on each?
– connexo
Nov 9 at 21:14
You don't need to manually add an ID to the element. This works as well:document.querySelectorAll('.results')[0].getElementsByTagName('img')
– Will
Nov 9 at 21:17
1
@Will Why would you dodocument.querySelectorAll('.results')[0]
when you can just do the natural thingdocument.querySelector('.results')
?
– connexo
Nov 9 at 21:19
No, you can't. I don't know what is your main purpose. You're trying to learn JS or just want to download those images. If you want to learn, do other things since there still be a lot to learn. If you want to scrape those images, take a look at casperJS.
– vnt
Nov 9 at 21:21
@connexo Indeed. Old habits!
– Will
Nov 9 at 21:25
Would you be satisfied with a solution that opens new tabs for each img so you can simply tab through them and press CTRL-S on each?
– connexo
Nov 9 at 21:14
Would you be satisfied with a solution that opens new tabs for each img so you can simply tab through them and press CTRL-S on each?
– connexo
Nov 9 at 21:14
You don't need to manually add an ID to the element. This works as well:
document.querySelectorAll('.results')[0].getElementsByTagName('img')
– Will
Nov 9 at 21:17
You don't need to manually add an ID to the element. This works as well:
document.querySelectorAll('.results')[0].getElementsByTagName('img')
– Will
Nov 9 at 21:17
1
1
@Will Why would you do
document.querySelectorAll('.results')[0]
when you can just do the natural thing document.querySelector('.results')
?– connexo
Nov 9 at 21:19
@Will Why would you do
document.querySelectorAll('.results')[0]
when you can just do the natural thing document.querySelector('.results')
?– connexo
Nov 9 at 21:19
No, you can't. I don't know what is your main purpose. You're trying to learn JS or just want to download those images. If you want to learn, do other things since there still be a lot to learn. If you want to scrape those images, take a look at casperJS.
– vnt
Nov 9 at 21:21
No, you can't. I don't know what is your main purpose. You're trying to learn JS or just want to download those images. If you want to learn, do other things since there still be a lot to learn. If you want to scrape those images, take a look at casperJS.
– vnt
Nov 9 at 21:21
@connexo Indeed. Old habits!
– Will
Nov 9 at 21:25
@connexo Indeed. Old habits!
– Will
Nov 9 at 21:25
|
show 1 more comment
2 Answers
2
active
oldest
votes
up vote
1
down vote
accepted
Quick answer would be no, javascript can't really download files onto your machine.
You don't really need JS to get the image urls, since each one is the same url preceeded with the pokemons pokedex number
https://assets.pokemon.com/assets/cms2/img/pokedex/detail/004.png
004 being the pokemon number
You could iterate this number in say a python script, which could download the images.
add a comment |
up vote
0
down vote
One could create an array with all absolute links. Then create a temporary anchor tag <a>
which holds the image as a source. Then use the click event to download it. However your browser needs to be compatible
var links = [ "https://assets.pokemon.com/assets/cms2/img/pokedex/detail/001.png", "https://assets.pokemon.com/assets/cms2/img/pokedex/detail/002.png"]
function download(uri, name)
var link = document.createElement("a");
link.download = name;
link.href = uri;
link.click();
var counter = 0;
for (i = 0; i < links.length; i++)
download(links[i], "pokemon "+ counter);
counter++;
First time i excuted this i was navigated to the website of pokemon.com. when i tried it in their developer console it worked (chrome version 70.xxx) I had to give consent though by pressing Allow
:
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
Quick answer would be no, javascript can't really download files onto your machine.
You don't really need JS to get the image urls, since each one is the same url preceeded with the pokemons pokedex number
https://assets.pokemon.com/assets/cms2/img/pokedex/detail/004.png
004 being the pokemon number
You could iterate this number in say a python script, which could download the images.
add a comment |
up vote
1
down vote
accepted
Quick answer would be no, javascript can't really download files onto your machine.
You don't really need JS to get the image urls, since each one is the same url preceeded with the pokemons pokedex number
https://assets.pokemon.com/assets/cms2/img/pokedex/detail/004.png
004 being the pokemon number
You could iterate this number in say a python script, which could download the images.
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
Quick answer would be no, javascript can't really download files onto your machine.
You don't really need JS to get the image urls, since each one is the same url preceeded with the pokemons pokedex number
https://assets.pokemon.com/assets/cms2/img/pokedex/detail/004.png
004 being the pokemon number
You could iterate this number in say a python script, which could download the images.
Quick answer would be no, javascript can't really download files onto your machine.
You don't really need JS to get the image urls, since each one is the same url preceeded with the pokemons pokedex number
https://assets.pokemon.com/assets/cms2/img/pokedex/detail/004.png
004 being the pokemon number
You could iterate this number in say a python script, which could download the images.
answered Nov 9 at 21:14
SpeedOfRound
441212
441212
add a comment |
add a comment |
up vote
0
down vote
One could create an array with all absolute links. Then create a temporary anchor tag <a>
which holds the image as a source. Then use the click event to download it. However your browser needs to be compatible
var links = [ "https://assets.pokemon.com/assets/cms2/img/pokedex/detail/001.png", "https://assets.pokemon.com/assets/cms2/img/pokedex/detail/002.png"]
function download(uri, name)
var link = document.createElement("a");
link.download = name;
link.href = uri;
link.click();
var counter = 0;
for (i = 0; i < links.length; i++)
download(links[i], "pokemon "+ counter);
counter++;
First time i excuted this i was navigated to the website of pokemon.com. when i tried it in their developer console it worked (chrome version 70.xxx) I had to give consent though by pressing Allow
:
add a comment |
up vote
0
down vote
One could create an array with all absolute links. Then create a temporary anchor tag <a>
which holds the image as a source. Then use the click event to download it. However your browser needs to be compatible
var links = [ "https://assets.pokemon.com/assets/cms2/img/pokedex/detail/001.png", "https://assets.pokemon.com/assets/cms2/img/pokedex/detail/002.png"]
function download(uri, name)
var link = document.createElement("a");
link.download = name;
link.href = uri;
link.click();
var counter = 0;
for (i = 0; i < links.length; i++)
download(links[i], "pokemon "+ counter);
counter++;
First time i excuted this i was navigated to the website of pokemon.com. when i tried it in their developer console it worked (chrome version 70.xxx) I had to give consent though by pressing Allow
:
add a comment |
up vote
0
down vote
up vote
0
down vote
One could create an array with all absolute links. Then create a temporary anchor tag <a>
which holds the image as a source. Then use the click event to download it. However your browser needs to be compatible
var links = [ "https://assets.pokemon.com/assets/cms2/img/pokedex/detail/001.png", "https://assets.pokemon.com/assets/cms2/img/pokedex/detail/002.png"]
function download(uri, name)
var link = document.createElement("a");
link.download = name;
link.href = uri;
link.click();
var counter = 0;
for (i = 0; i < links.length; i++)
download(links[i], "pokemon "+ counter);
counter++;
First time i excuted this i was navigated to the website of pokemon.com. when i tried it in their developer console it worked (chrome version 70.xxx) I had to give consent though by pressing Allow
:
One could create an array with all absolute links. Then create a temporary anchor tag <a>
which holds the image as a source. Then use the click event to download it. However your browser needs to be compatible
var links = [ "https://assets.pokemon.com/assets/cms2/img/pokedex/detail/001.png", "https://assets.pokemon.com/assets/cms2/img/pokedex/detail/002.png"]
function download(uri, name)
var link = document.createElement("a");
link.download = name;
link.href = uri;
link.click();
var counter = 0;
for (i = 0; i < links.length; i++)
download(links[i], "pokemon "+ counter);
counter++;
First time i excuted this i was navigated to the website of pokemon.com. when i tried it in their developer console it worked (chrome version 70.xxx) I had to give consent though by pressing Allow
:
answered Nov 9 at 21:24
Baklap4
1,34011235
1,34011235
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53233289%2fdownload-images-from-array%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Would you be satisfied with a solution that opens new tabs for each img so you can simply tab through them and press CTRL-S on each?
– connexo
Nov 9 at 21:14
You don't need to manually add an ID to the element. This works as well:
document.querySelectorAll('.results')[0].getElementsByTagName('img')
– Will
Nov 9 at 21:17
1
@Will Why would you do
document.querySelectorAll('.results')[0]
when you can just do the natural thingdocument.querySelector('.results')
?– connexo
Nov 9 at 21:19
No, you can't. I don't know what is your main purpose. You're trying to learn JS or just want to download those images. If you want to learn, do other things since there still be a lot to learn. If you want to scrape those images, take a look at casperJS.
– vnt
Nov 9 at 21:21
@connexo Indeed. Old habits!
– Will
Nov 9 at 21:25