搜ijsio 发表于 2018-9-20 13:39:27

golang写一个简单的爬虫

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



页: [1]
查看完整版本: golang写一个简单的爬虫