Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

152
Vistas
Extract source link from <img> tags when a url is given using Javascript (Aimed at Facebook posts page)

Is there any method by which I can get url inside <img> tag from a link.

Eg: When I give a link of website, like a website or facebook page, I want to get all urls inside all the img tags in that site --> <*img src="url">

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

First send a request to a page, get the content and parse it to html. Then get all img tags by using getElementsByTagName method.

For example, if you want to get all img tags on https://jsonplaceholder.typicode.com, your code should be like below.

fetch('https://jsonplaceholder.typicode.com').then(function (response) {
    // The API call was successful!
    return response.text();
}).then(function (html) {

    // Convert the HTML string into a document object
    var parser = new DOMParser();
    var doc = parser.parseFromString(html, 'text/html');
    var imgTags = doc.getElementsByTagName("img");
    console.log(imgTags);
    
    var imgTagArr = [...imgTags];
    imgTagArr.forEach(img => console.log(img.src)); //iterate the all img tag srcs
}).catch(function (err) {
    // There was an error
    console.warn('Something went wrong.', err);
});

Example output:

json

about 4 years ago · Juan Pablo Isaza Denunciar

0

Yup , in Html like <img class="pqr" url ="xxxxxxx-yyy"/>
in Js file:

const img =document.querySelector('.pqr')
img.src // <-- this will give the src of the image 
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda