golang 转换相对URL到绝对URL

func fixUrl(href, base string) (string) {  
  uri, err := url.Parse(href)              
  if err != nil {                          
    return ""                              
  }                                        
  baseUrl, err := url.Parse(base)          
  if err != nil {                          
    return ""
  }
  uri = baseUrl.ResolveReference(uri)
  return uri.String()                      
}

来自Build a Web Crawler in Go

发表评论