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

  

上一篇:js eval函数写一个简单的计算器


下一篇:Python写一个简单的爬虫