def base
      @base = if doc
                href = doc.search('//head/base/@href')
                URI(href.to_s) unless href.nil? rescue nil
              end unless @base

      return nil if @base && @base.to_s.empty?
      @base
    end
def base
      @base = if doc
                href = doc.search('//head/base/@href')
                URI(href.to_s) unless href.nil? rescue nil
              end unless @base

      return nil if @base && @base.to_s.empty?
      @base
    end
Base URI from the HTML doc head element
 http://www.w3.org/TR/html4/struct/links.html#edef-BASE