pyList

go net/http 抓取网页内容

go net/http 抓取网页内容

package main
 
import (
    "fmt"
    "net/http"
    "io/ioutil"
    "os"
    )
 
func main() {
    response, err := http.Get("http://www.baidu.com/")
    if err != nil {
        fmt.Printf("%s", err)
        os.Exit(1)
    } else {
        defer response.Body.Close()
        contents, err := ioutil.ReadAll(response.Body)
        if err != nil {
            fmt.Printf("%s", err)
            os.Exit(1)
        }
        fmt.Printf("%s\n", string(contents))
    }
}
本文网址: https://pylist.com/t/1435045677 (转载注明出处)
如果你有任何建议或疑问可以在下面 留言
Be the first to comment!
Captcha image
Relative Articles