5

I need to download all page links from http://en.wikipedia.org/wiki/Meme and save them to a file all with one command.

First time using the commmand line so I'm unsure of the exact commands, flags, etc to use. I only have a general idea of what to do and had to search around for what href means.

wget http://en.wikipedia.org/wiki/Meme -O links.txt | grep 'href=".*"' | sed -e 's/^.*href=".*".*$/\1/'

The output of the links in the file does not need to be in any specific format.

cajole0110
  • 51
  • 1
  • 2

3 Answers3

4

Using gnu grep:

grep -Po '(?<=href=")[^"]*' links.txt

or with wget

wget http://en.wikipedia.org/wiki/Meme -q -O - |grep -Po '(?<=href=")[^"]*'
BMW
  • 42,880
  • 12
  • 99
  • 116
  • You may also want to add the `-q` flag, to prevent printing the progress bar interleaved with the actual output (the progress bar is printed to stderr, so it doesn't interfere as such, it just looks funky). – Martin Tournoij Feb 19 '14 at 00:17
1

You could use wget's spider mode. See this SO answer for an example.

wget spider

Community
  • 1
  • 1
Ken
  • 7,847
  • 1
  • 21
  • 20
0
wget http://en.wikipedia.org/wiki/Meme -O links.txt | sed -n 's/.*href="\([^"]*\)".*/\1/p'

but this only take 1 href per line, if there is more than 1, other are lost (same as your original line). You also forget to have a group (\( -> \)) in your orginal sed first pattern so \1 refere to nothing

NeronLeVelu
  • 9,908
  • 1
  • 23
  • 43