Go抓取网页


package main

import (
	"fmt"
	"io/ioutil"
	"net/http"
)

func HttpGet(url string) string {
	request, err := http.Get(url)
	if err != nil {
		return ""
	}

	defer request.Body.Close()
	respone, err := ioutil.ReadAll(request.Body)
	if err != nil {
		return ""
	}

	return string(respone)
}

func main() {
	html := HttpGet("http://www.mogublog.net")
	fmt.Println(html)
}