pbpaste ftw

Jan 11, 2007 16:54

I wanted to download all the mp3's from the the Best of Bootie 2006 CD website, but there wasn't a way to download all the files at once. I got around this by doing the following in Firefox:
  1. Select all the text on the page containing links to the files.
  2. Right-click on the text that was just selected.
  3. Pick "View Selection Source".
  4. When the DOM Source of Selection opens, Right-click on the selected HTML and pick "Copy".
  5. Open a Terminal and "cd" to the location I want to save the files in.
  6. Type in the following command: "pbpaste | tr \> \\n | grep href | cut -d '"' -f 2 | xargs wget"
What this does:
  • "pbpaste" is a Mac OS X command line utility that allows you to print out the clipboard ("xsel" is an equivalent in Linux). This prints out the HTML that I selected in step 4 above.
  • "tr" replaces characters. I replaced the right angle bracket with a carriage return, so that every HTML tag was is on a separate line.
  • "grep" searches text. I looked for "href" which gave me every link in the selected text
  • "cut" can give you specific columns of text based on a separator you give it. I said to split at double quotes and give me the second column (the mp3).
  • "xargs" takes input and will run a command with each input line as the argument of the command.

pbpaste, command, macosx, osx, line

Previous post Next post
Up