在使用go语言编写爬虫脚本时,会发现对于部分网站会报error: Get "https://x.x.x../simple/view/login.html": x509: certificate signed by unknown authority的错误。此时只要强制关闭request访问时的ssl验证即可。

var url string
url := "https://www.baidu.com"
tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
client := &http.Client{Transport: tr,Timeout: 5*time.Second}
req, _ := http.NewRequest("GET", url, nil)
resp, err := client.Do(req)
if err != nil {
log.Fatal("访问出错")
}
本文介绍了在Go语言爬虫中遇到的SSL证书错误,并提供了解决方案,即如何通过设置`http.Transport`的TLS配置为不验证证书。
410

被折叠的 条评论
为什么被折叠?



