I'm looking for a method to reliably extract the host name from a URL string in Ruby.
e.g. http://www.mglenn.com/directory = www.mglenn.com OR http://www.mglenn.com?param=x = www.mglenn.com
You could try something like this:
require 'uri' myUri = URI.parse( 'http://www.mglenn.com/directory' ) print myUri.host # => www.mglenn.com
URI("http://www.mglenn.com/directory").host
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With