Javascript issue while downloading images

#1

I am going through the 2019 course and trying to download images as shown in the video of lesson 2. https://course.fast.ai/videos/?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); window.open('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?

Unmesh

2 Likes

(J Vitor Mascarenhas) #2

Hi,
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.

16 Likes

(Oliver W.) #3

This works for me, many thanks!

0 Likes

(Arjun Singh) #4

Hello I am 2nd year b.tech 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

0 Likes

(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.

0 Likes

(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>`;
0 Likes

(Glenn Sampson) #9

I had this issue

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

3 Likes

(Bright Sora) #10

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

0 Likes

(Bright Sora) #11

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

0 Likes

#12

Thank you! This worked!

0 Likes

#13

Thank you, it worked!

0 Likes

(moragb) #14

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

0 Likes

(Antanas) #15

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!

0 Likes

(Phil Marnell) #16

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?

0 Likes

(Phil Marnell) #17

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

1 Like