Javascript issue while downloading images

Thank you! This worked!

Thank you, it worked!

Hi everyone,
I had this problem too, I suggest to check AddBlock / AddBlockPluse, and turn them off.

Hey, it seems that I’ve tried all the variations of codes I found there also in Incognito but nothing really works. Mostly I have empty files. Can someone help me?
Thanks in advance!

Having the same problem - it creates an empty file. I’ve tried the variations (including incognito mode) and FF and Chrome.

Has anyone found a workaround or explanation?

YAY!

Thanks @zaryabmakram. It worked and for anyone else stuck:

  • Disabled Chrome extensions
  • Ran in ‘incognito’ mode
  • Entered the Google image query - ==>then went to the bottom of the results<==
  • F12 to enter console mode
  • Pasted this into the console and pressed ENTER -

javascript:document.body.innerHTML = <a href="data:text/csv;charset=utf-8,${escape(Array.from(document.querySelectorAll('.rg_di .rg_meta')).map(el=>JSON.parse(el.textContent).ou).join('\n'))}" download="links.txt">download urls</a>;

2 Likes

Thanks @zaryabmakram & @lowcountrypj I managed to download a file of links using your instructions and code snippet after much frustration and your posts are appreciated. The only thing I had to change was that I had to go to the post from @zaryabmakram from August and retrieve the original code snippet from the markdown formatted post, I believe posting the code directly into text seems to mess up the single quotes in the code:

document.body.innerHTML = `<a href="data:text/csv;charset=utf-8,${escape(Array.from(document.querySelectorAll('.rg_di .rg_meta')).map(el=>JSON.parse(el.textContent).ou).join('\n'))}" download="urls_${document.getElementsByName("q")[0].value.split(" ").join("_")}.csv">download urls</a>`;

I am new to this but have just learned that to post code blocks using markdown you put 3 backticks on before and after the code, you can also optionally add the language name after the first set of back ticks to add syntax highlighting, in this case javascript. if you want to post inline code you just use a single backtick. I am really just paraphrasing the information on markdown that I found here

Hi
I am facing the same issue . I tried using your code. However the file that downloaded is a empty file. I tried the original command and your command in incognito mode. But it didn’t help. I am using Chrome browser .Any ideas?

With some digging , this worked for me
var urls=Array.from(document.querySelectorAll('.rg_i')).map(el=> el.hasAttribute('data-src')?el.getAttribute('data-src'):el.getAttribute('data-iurl'));
var hiddenElement = document.createElement('a');
hiddenElement.href = 'data:text/csv;charset=utf-8,' + encodeURI(urls.join('\n'));
hiddenElement.target = '_blank';
hiddenElement.download = 'myFile.txt';
hiddenElement.click();

14 Likes

this was the only solution that worked for me, thanks a lot :slight_smile:

1 Like

only this solution worked for me

1 Like

thanks. out of 5 other solutions only this worked for me

Still I find that file empty.

try my code in Chrome
var urls=Array.from(document.querySelectorAll('.rg_i')).map(el=> el.hasAttribute('data-src')?el.getAttribute('data-src'):el.getAttribute('data-iurl')); var hiddenElement = document.createElement('a'); hiddenElement.href = 'data:text/csv;charset=utf-8,' + encodeURI(urls.join('\n')); hiddenElement.target = '_blank'; hiddenElement.download = 'myFile.csv'; hiddenElement.click();

Hi,
I am stuck on the same problem. I tried all the solutions provided on this conversation but the links are encrypted and not similar in any way to what Jeremy showed in his lecture. The initial 10-12 lines in the file are blank and the links are like -
https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcRs_kltkyTFFAwOBwk0kzj3y9IaDCMV300BiqzzN0HZywy05zg9&usqp=CAU

Also, I am using Microsoft Edge Chromium, is it necessary to use Google Chorme?

Thanks!

Hi,

Generating the csv file after removing all the null urls solved the problem for me. Give it a try!

var urls=Array.from(document.querySelectorAll('.rg_i')).map(el=> el.hasAttribute('data-src')?el.getAttribute('data-src'):el.getAttribute('data-iurl'));
var filtered = urls.filter(function (el) {
  return el != null;
});
var hiddenElement = document.createElement('a');
hiddenElement.href = 'data:text/csv;charset=utf-8,' + encodeURI(filtered.join('\n'));
hiddenElement.download = 'file.csv';
hiddenElement.click();

Unfortunately this will only get you a small size images that google downsized for the matrix display. To get the original size image one needs to click on the image, then a new “frame” opens where you can get the link to the original image. Unfortunately, I do not know the web scarping enough to make a javascript or python to put this procedure in a script.

After of digging 3 Hours this is the only with works for me. I used it in Chrome, Safary , Firefox

Thanks a Lot!!!

Check out this extension for Chrome:

much easier…

bro I have some problem about download the data into the urls in fastai library
urls = Array.from(document.querySelectorAll(’.rg_di .rg_meta’)).map(el=>JSON.parse(el.textContent).ou);
window.open(‘data:text/csv;charset=utf-8,’ + escape(urls.join(’\n’)));

this might not work … in my side please helpe mee
if you have any other idea