Quickly Copy HTML & CSS Source to the Clipboard with curl

Apr 9, 2011 - 4 Comments

using curl Using curl and pbcopy, we can quickly grab and copy HTML and CSS code from any URL via the command line. This should be a helpful tip for the web developers out there, but for anyone looking to check the source of a web page through this can be an invaluable little trick.

Getting HTML is just a matter of pointing curl to the URL in question, then piping the results to the pbcopy command like so:

curl "http://google.com/" | pbcopy

Of course you’ll want to replace the sample URL with your own. When the command has finished running, the HTML will now be in your clipboard (thanks to pbcopy) and ready for you to paste anywhere else.

Grabbing the CSS requires you to specify where the CSS file is located, otherwise the command is the same:

curl "http://google.com/css/stylesheet.css" | pbcopy

We’ve covered pbcopy & pbpaste a while ago, they’re just command line interfaces for the Mac OS X clipboard but combined with other scripts or utilities can be quite powerful.

If you want to go a step further, you can also quickly mirror a website locally using wget or backup through FTP with wget.

This works in OS X, though it’s not directly compatible with linux because of the pbcopy command.

.

Related articles:

Posted by: David Mendez in Command Line

4 Comments

» Comments RSS Feed

  1. ubru bey says:

    how thoughtful..making it easy to everyone huh..thanks this would help.:)

  2. […] Line, Tips & Tricks – July 16th, 2011 – Leave a Comment Using curl we can retrieve the HTML & CSS source code of any specified URL and even the http header info, but some sites serve completely […]

  3. […] involved with the web should get some good use out of the header trick, and web developers can also use curl to copy all the HTML and CSS from a website very quickly. stLight.options({ […]

  4. Chuck says:

    you could use this for more than html and css

Leave a Reply

 

Shop on Amazon.com and help support OSXDaily!

Subscribe to OSXDaily

Subscribe to RSS Subscribe to Twitter Feed Follow on Facebook Subscribe to eMail Updates

Tips & Tricks

News

iPhone / iPad

Mac

Troubleshooting

Shop on Amazon to help support this site