Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

167
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda