123456789101112131415161718192021222324 |
- package util
- import (
- "io"
- "net/http"
- )
- func GetHtml(url string) ([]byte, error) {
- request, err := http.NewRequest("GET", url, nil)
- if err != nil {
- return nil, err
- }
- // 设置请求投
- request.Header.Add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8")
- request.Header.Add("Accept-Language", "zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3")
- request.Header.Add("Connection", "keep-alive")
- request.Header.Add("User-Agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36")
- client := http.Client{}
- response, err := client.Do(request)
- if err != nil {
- return nil, err
- }
- return io.ReadAll(response.Body)
- }
|