Showing posts with label curl. Show all posts
Showing posts with label curl. Show all posts

Friday, July 29, 2011

Get links from a page with bash

Get anchor elements from a webpage can be done with

curl URL 2>&1 | grep -o -E 'href="([^"#]+)"' | cut -d'"' -f2


where you replace URL with your choice, just like here:
curl http://cookpad.com 2>&1 | grep -o -E 'href="([^"#]+)"' | cut -d'"' -f2

Thursday, April 21, 2011

Get HTTP status code with curl in bash


curl --write-out %{http_code} --silent --output /dev/null URL

and then wrapping it into a function

getHTTPCode () {
echo $(curl --write-out %{http_code} --silent --output /dev/null $1)
}

response=$(getHTTPCode URL)
echo $response