Go Crawer Basic
請求
func GetMyRequest(){
}
func GetEmail(url string)(Content string){
resp,err := http.Get(url)
HandlerError(err,"http.GetUrl:獲取網址錯誤")
defer resp.Body.Close()
ContentBinary,err:=ioutil.ReadAll(resp.Body)
HandlerError(err,"ioutil.ReadAll:解析二進制")
Content=string(ContentBinary)
//正規表達式,0
resp.MustCompile(`(\d+)@gmail.com`)
}
//處理異常
func HandleError(err Error,reason string){
if err!= nil{
fmt.Println(reason,err)
}
}
func Main(){
GetEmail("https://www.www.www")
}
正規表達式
html_str := "<td class="title">《阿凡達》<span>Avatar</span></td>"
temp_str := `<td class="title">(.*?)<span>(.*?)</span></td>`
//印出《阿凡達》