go爬虫
2021/8/15 23:06:37
本文主要是介绍go爬虫,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
package main import ( "fmt" "io/ioutil" "net/http" "github.com/gin-gonic/gin" ) func get_baidu(url string) string{ client := &http.Client{} req, _ := http.NewRequest("GET", url, nil) req.Header.Set("User-Agent", "Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Mobile Safari/537.36") res, err := client.Do(req) if err != nil{ fmt.Println("get error") return "" } defer res.Body.Close() body, err := ioutil.ReadAll(res.Body) if err != nil{ fmt.Println("body error") return "" } return string(body) } func main() { r := gin.Default() name := "asf" html := get_baidu("https://www.baidu.com/s?wd="+name) fmt.Printf(html) }
爬一下百度,然后本来想用gin返回的,可惜ide过期没调好
这篇关于go爬虫的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-06-26解决google chrome helper 内存占用较高!
- 2024-04-01got an unexpected keyword argument
- 2024-03-30维多利亚的秘密 golang入坑系统
- 2024-03-29mongodb sort by date
- 2024-03-29go swagger
- 2024-03-25mongodb cdc
- 2024-03-25how to use go in vscode
- 2024-03-22mongooseserverselectionerror: connect econnrefused ::1:27017
- 2024-03-21pymongo insert_many
- 2024-03-18projection mongodb