Загрузка...

Pictures from the HTML file

Thread in Frontend created by Mananeymon Apr 14, 2025. 274 views

  1. Mananeymon
    Mananeymon Topic starter Apr 14, 2025 1 Nov 6, 2024
    Здравствуйте, наверно тупой вопрос, но все равно задам. Есть файл html, внутри него много картинок. Есть ли способ как вытащить все эти картинки, без клика на каждого и сохранения по отдельности?
     
  2. Y4sperMaglot
    с помощью querySelector находишь теги img и всё у тебя массив элементов img, можешь вытащить из каждого ссылку на картинку например с помощью forEach
     
    1. View previous comments (27)
    2. Mananeymon Topic starter
    3. Y4sperMaglot
      Mananeymon, скинь ссылку на страницу откуда картинки парсишь
    4. Mananeymon Topic starter
    5. View the next comments (1)
  3. ezbooz
    ezbooz Apr 14, 2025 994 Mar 29, 2018
    1. Апатия
      ezbooz, такие расширения не работают в html файлах
    2. Mananeymon Topic starter
      ezbooz, минус, не работает
  4. Апатия
    Апатия Apr 14, 2025 444 1201 Jun 15, 2021
    JS
    (function() {
    const imageExtensions = ['.jpg', '.jpeg', '.png', '.gif', '.webp', '.bmp', '.svg', '.tiff'];

    const imgTags = Array.from(document.querySelectorAll('img'))
    .map(img => img.src);

    const aTags = Array.from(document.querySelectorAll('a'))
    .map(a => a.href)
    .filter(href => imageExtensions.some(ext => href.toLowerCase().includes(ext)));

    const allImageLinks = Array.from(new Set([...imgTags, ...aTags]));

    console.log('links:', allImageLinks.length);
    console.log(allImageLinks);
    })();
    Ну вообще что то типо такого, как все скачать по ссылкам я уж надеюсь поймешь?
     
Loading...
Top