golang写一个简单的爬虫

mac2022-06-30  19

package main import( "fmt" "io/ioutil" "net/http" ) func gethtml(url string) (r *http.Response, e error){ resp,err := http.Get(url) if err != nil { fmt.Print("error") } return resp,err } func main(){ resp, _ :=gethtml("http://www.baidu.com") defer resp.Body.Close() fmt.Println(resp.StatusCode) if resp.StatusCode==http.StatusOK{ body,err :=ioutil.ReadAll(resp.Body) if err !=nil{ fmt.Println(err) } fmt.Println(string(body))

  

转载于:https://www.cnblogs.com/c-x-a/p/9141748.html

最新回复(0)