2014-07-27 138 views
1

在Python中,我們有urllib2和httplib,但我一直在Go中搜索!頁面,我只發現了一個http lib,我不知道這個lib是否相同。是否有類似Python的urllib2的庫?

+0

Go的默認http客戶端非常好,你真的不需要別的東西。只是用它! –

+0

已經[在golang-nuts郵件列表中討論](https://groups.google.com/d/topic/golang-nuts/RnBF9Tlzfqc/discussion)。 – kostix

回答

0

如果您想要落後於主要的golang http package,您可以使用像go-metainspector這樣的項目。
它與python urllib2類似,它返回頁面的元信息,例如標題。

go-metainspector是一個網絡抓取工具包,可以訪問給定網址的基本信息和元標記。

url := "http://www.cloudcontrol.com/pricing" 
    MI, err := metainspector.New(url) 
    if err != nil { 
    fmt.Printf("Error: %v", err) 
    } else { 
    fmt.Printf("\nURL: %s\n", MI.Url()) 
    fmt.Printf("Scheme: %s\n", MI.Scheme()) 
    fmt.Printf("Host: %s\n", MI.Host()) 
    fmt.Printf("Root: %s\n", MI.RootURL()) 
    fmt.Printf("Title: %s\n", MI.Title()) 
    fmt.Printf("Language: %s\n", MI.Language()) 
    fmt.Printf("Author: %s\n", MI.Author()) 
    fmt.Printf("Description: %s\n", MI.Description()) 
    fmt.Printf("Charset: %s\n", MI.Charset()) 
    fmt.Printf("Feed URL: %s\n", MI.Feed()) 
    fmt.Printf("Links: %v\n", MI.Links()) 
    fmt.Printf("Images: %v\n", MI.Images()) 
    fmt.Printf("Keywords: %v\n", MI.Keywords()) 
    fmt.Printf("Compatibility: %v\n", MI.Compatibility()) 
} 
相關問題