Is there a way to download all .txt files from the page via curl or wget command

3

1

My question is in a title: Is there a way to download all .txt files from the page via curl or wget command? Thanks

kostyawhite

Posted 2015-02-13T12:21:30.417

Reputation: 33

Answers

3

You can use wget with -A to specify a type of file and -rto be recursive:

wget -r -A '*.txt' http://url-to-webpage-with-txts/

jcbermu

Posted 2015-02-13T12:21:30.417

Reputation: 15 868

1I've got an empty folders after this command – kostyawhite – 2015-02-13T12:31:17.553

Sorry, I made a mistake when formatting the command. Corrected. – jcbermu – 2015-02-13T12:52:28.197

I've tried this corrected one, but just got index.html – kostyawhite – 2015-02-13T13:00:42.237

I've tested on Linux Debian using bash. Is it possible that the txt files are behind an user/password authentication on the website? – jcbermu – 2015-02-13T13:05:24.357

No, it is possible to wget each file separately,here is link: http://introcs.cs.princeton.edu/java/21function/

– kostyawhite – 2015-02-13T14:09:47.753

I tried and only downloaded robots.txt. Are you sure that there are .txt files on that server? – jcbermu – 2015-02-13T14:29:37.000

Oh, my bad, this link : http://www.cs.princeton.edu/introcs/21function/

– kostyawhite – 2015-02-13T14:33:39.417

This is link to the same page, its okay, I'll download it manually, thanks for your help!:) – kostyawhite – 2015-02-13T14:36:15.553

I tried and it downloaded 10 txt files that were saved to the directory introcs.cs.princeton.edu/java/21function – jcbermu – 2015-02-13T14:36:36.977

I'm using debian/bash and i understand that you're using OSX. try using double-quotes instead of single-quotes. – jcbermu – 2015-02-13T14:40:45.537

Oh, thanks, the problem was about single-quotes, just that, thanks! – kostyawhite – 2015-02-13T14:54:43.677