0

I have an excel file where there are around 2,000 URLs (divided in 4 columns). If you go to a particular URL, you will find that there is a main image. I want to extract the src="" attribute from each URL so I can have the .JPG URL.

Here is an example of one of the urls: https://ibb.co/fXvLtVX

From that particular URL I need this address: https://i.ibb.co/VLm5D0L/Cuadros-Decorativos-Canvas-Revolution-Principal-REC-Liquido-De-Colores.png

Which is the src attribute of the main image.

Can I automate this task using JavaScript or any other tool?

Here is a screenshot of the Excel file where contains the URLs data.

enter image description here

Heretic Monkey
  • 11,687
  • 7
  • 53
  • 122
Daniel B
  • 39
  • 6

2 Answers2

2

You could definitely do it with JavaScript, or jQuery to make it simple.

To get a src attribute from an element in the DOM just use

var imageUrl = $("#image-viewer-container img").attr('src');

And if you have to read an excel file I suggest you to use the csv extension and just loop the links reading the file as previously answered here

The problem is that if you try to get the content of a page using JavaScript only you might stumble into No Access-Control-Allow-Origin problems, but there are many ways to avoid this.

The most simple is probably to add a PHP file and call that with jQuery.ajax method

$.ajax({
   type: "GET",
   url: "http://link-to-your/file.php",
   data: "url=" + encodeURIComponent(url),
   success: function(data)
    {        
        var image = $('#image-viewer-container img', $(data));
        var imageUrl = image.attr('src'); 
        // Do what you have to do with the image src
    } 
});

PHP File

<?php
header('Access-Control-Allow-Origin: *');  

$url = urldecode($_GET['url']);

echo file_get_contents($url);
Effe
  • 33
  • 1
  • 7
1

let me know if the following answer makes sense to you. If it does we can work on the code.

using javascript:

1) read in excel file (csv)
2) go to each link
3) get img.src
4) write  img.src to file
DCR
  • 14,737
  • 12
  • 52
  • 115
  • Hello! Thanks for your help. It makes a lot of sense. It would be ideal that the "writing img.src" be in the same position as the links are now. Best. – Daniel B Feb 05 '20 at 21:32