In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces how to solve the problem of how to do crawler status code return 418 in Go language. It is very detailed and has a certain reference value. Interested friends must finish reading it!
Background
When uses the go language as a crawler, it uses http.Get (url) to get the web page content. The status code returns 404, and the Body body is empty.
Cause analysis
http.Get (url) is a http request that does not need to set the header attribute, which is relatively simple and quick, but the status code returns 418, indicating that we need to set its header property, so we can use http.NewRequest to set its header attribute.
The code section func main7 () {client: = & http.Client {} url: = "https://movie.douban.com/top250?start=0&filter=" reqest, err: = http.NewRequest (" GET ", url, nil) / / sets the header property reqest.Header.Add (" User-Agent "," Mozilla/5.0 (Windows NT 10.0; Win64) " X64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36 OPR/66.0.3515.115 ") if erratic response {fmt.Println (err) return} response, _: = client.Do (reqest) defer response.Body.Close () buf: = make ([] byte 4096) var result string for {n Err:=response.Body.Read (buf) if n = 0 {fmt.Println ("read the web page completed") break} if erratic readers nil & & errors read io.EOF {fmt.Println ("resp body err") Err) return} result + = string (buf [: n]) / / print the read web page fmt.Println (result)}} above are all the contents of this article entitled "how to solve the problem of how to use Go language to return 418 crawler status codes" Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.