Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

149
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!