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?



(J Vitor Mascarenhas) #2

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.


(Oliver W.) #3

This works for me, many thanks!


(Arjun Singh) #4

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


(Abhin Sharma) #5

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.

1 Like

(skuit) #6

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

Thank you!v:)

1 Like

(Biswajit Ghoshal) #7

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.


(Zaryab Akram) #8

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

(Glenn Sampson) #9

I had this issue

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

1 Like

(Bright Sora) #10

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


(Bright Sora) #11

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