Javascript issue while downloading images

I am going through the 2019 course and trying to download images as shown in the video of lesson 2.

In this lesson, there are some instruction on how to download images. Here is the code from the course:
urls = Array.from(document.querySelectorAll('.rg_di .rg_meta')).map(el=>JSON.parse(el.textContent).ou);'data:text/csv;charset=utf-8,' + escape(urls.join('\n')));

The course notes says something like " I hit enter and it downloads my file for me. So I would call this teddies.txt and press “Save”.

But exact same javascript code is not opening up any text file for me. I checked my browser’s pop up settings too. What am I missing?



I used this other line I found on the Forum and it worked, a .txt file was created:

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>`;

You can change the name of the file changing the links.txt part.


This works for me, many thanks!

Hello I am 2nd year student and know only basic python,i recently watched 1 video on deep learning but could not understand the whole stuff. please tell me how to get started in fast ai, I am just a beginner and want to learn ai. Thanks

Step by step my man. Inch by inch. Get a little bit better every day. It all eventually comes together. I too have mostly a finance background and kind of self-learned Python and am working through the FastAi course. Trust yourself and work hard. Feel free to message me if you have anything further.


Hi, I can download the file, but it’s always empty. May I know what I could have been missed?

Thank you!v:)


Please do it in Chrome browser - it will work fine. I tried whole day today trying to do it in Firefox and IE - and finally succeeded in Chrome.

I have modified the snippet. Now you do not have to rename the file after downloading. Your google search query is used as the filename.

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 had this issue

Steps i used to resolve
Remove or Disable any chrome extensions
Run Incognito


Yep, It worked for me in incognito mode! Thanks alot!

1 Like

This worked for me!. Thanks But then you have to convert it to csv. Try the original code in incognito mode.

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?


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>;


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

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')); = '_blank'; = 'myFile.txt';;