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?










share|improve this question





















  • 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 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










  • @connexo Indeed. Old habits!
    – Will
    Nov 9 at 21:25














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?










share|improve this question





















  • 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 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










  • @connexo Indeed. Old habits!
    – Will
    Nov 9 at 21:25












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?










share|improve this question













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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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 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










  • @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











  • 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 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










  • @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












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.






share|improve this answer



























    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: First time i ran this script2nd time while on their website






    share|improve this answer




















      Your Answer






      StackExchange.ifUsing("editor", function ()
      StackExchange.using("externalEditor", function ()
      StackExchange.using("snippets", function ()
      StackExchange.snippets.init();
      );
      );
      , "code-snippets");

      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "1"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













       

      draft saved


      draft discarded


















      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

























      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.






      share|improve this answer
























        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.






        share|improve this answer






















          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.






          share|improve this answer












          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.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 9 at 21:14









          SpeedOfRound

          441212




          441212






















              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: First time i ran this script2nd time while on their website






              share|improve this answer
























                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: First time i ran this script2nd time while on their website






                share|improve this answer






















                  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: First time i ran this script2nd time while on their website






                  share|improve this answer












                  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: First time i ran this script2nd time while on their website







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 9 at 21:24









                  Baklap4

                  1,34011235




                  1,34011235



























                       

                      draft saved


                      draft discarded















































                       


                      draft saved


                      draft discarded














                      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





















































                      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







                      Popular posts from this blog

                      Use pre created SQLite database for Android project in kotlin

                      Darth Vader #20

                      Ondo