3 ms·
html.Parse takes a io.Reader https://github.com/golang/net/blob/master/html/parse.go#L2016 https://github.com/golang/net/blob/master/html/parse.go#L201... an h
by zalmoxes 10y ago
html.Parse takes a io.Reader https://github.com/golang/net/blob/master/html/parse.go#L2016 https://github.com/golang/net/blob/master/html/parse.go#L201...
an http Response.Body is a io.ReadCloser so you can pass it directly with `html.Parse(response.Body)`
But don't forget to defer io.Close the body.
- thatusernametho 10y agoI guess I wasn't specific enough. I'd like to stream the response so as to use less memory. I also need to ensure the body is utf-8 encoded because that makes Go happy. https://mionskowski.pl/html-golang-stream-processing https://mionskowski.pl/html-golang-stream-processing