有没有类似于Python的urllib2的库?

huangapple go评论80阅读模式
英文:

Is there library similar to urllib2 of Python?

问题

在Python中,我们有urllib2和httplib,但是我在Go!页面上搜索时只找到了一个http库,我不知道这个库是否相同。

英文:

In python we have urllib2 and httplib but I've been searching in Go! page and I only found an http lib, I don't know if this lib is the same.

答案1

得分: 0

如果你想深入了解golang http的内部,你可以使用像go-metainspector这样的项目。它类似于python urllib2,可以返回页面的元信息,如头部信息。

go-metainspector是一个网络爬虫包,提供对给定URL的基本信息和元标签的访问。

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())
}
英文:

If you want to go behind the main golang http package, you can use a project like go-metainspector.
It is similar to python urllib2 which return the meta-information of the page, such as headers.

> go-metainspector is a web scraper package that provides access to basic info and meta tags of a given URL.

  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())
}

答案2

得分: 0

我不确定你在urllib2中具体寻找什么,因为它有几个功能。但是,我找到了这段代码,它具备主要的要求:http://play.golang.org/p/Iq91LjcAka

希望这是你要找的内容。我还在Google Groups的这个讨论串中找到了它:https://groups.google.com/forum/#!topic/Golang-Nuts/RnBF9Tlzfqc

英文:

I don't know exactly what you are looking for in the urllib2, because it has several features. But, I have found this code with the main requisite: http://play.golang.org/p/Iq91LjcAka

I hope it is what you're looking for. I also found it in this thread of conversation in google groups: https://groups.google.com/forum/#!topic/Golang-Nuts/RnBF9Tlzfqc

huangapple
  • 本文由 发表于 2014年7月27日 19:09:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/24980317.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定