1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
| package fetcher
import ( "bufio" "fmt" "golang.org/x/net/html/charset" "golang.org/x/text/encoding" "golang.org/x/text/encoding/unicode" "golang.org/x/text/transform" "io/ioutil" "log" "net/http" "strings" )
func Fetch(url string) ([] byte, error) {
newUrl := strings.Replace(url, "http://", "https://", 1)
request, _:=http.NewRequest(http.MethodGet,newUrl,nil) request.Header.Add("User-Agent","Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1")
cookie := "ec=efexs2yx-1635059763651-4354f6812c7ee-1160473905; FSSBBIl1UgzbN7NO=50VBKV5hc0utxjqurAbThL2oOHItIEhFghdO1gdWyFhazAg7AKjmWBYnVMsPSVDRiSAKC1Xi7Q2JXDaDrAzn2ZA; sid=WoTVURTyXnfFuyrLjyvP; _exid=SOFFj%2B9FuKQsSSQgAHQq1wFmbHHxiumUgMg4agh6CvCmn1kBX5i%2FP3FzOUtJH99IXis2NS1cc7PdW1UAoVTmSA%3D%3D; _efmdata=7d%2FA9aWpDcKzs29MsTO%2BMHTqjG75uCjz%2BbNOD2sXTBvXMYfHCfSN3NSqzEYUGO5tguKli8YS2L9O%2BK0VpRv%2BFuWqAGZg0j5PpOcDcQTauuM%3D; FSSBBIl1UgzbN7NP=53UVQdDmToH3qqqmZ7Uve0qwxpoCJMOOrBMPxhuW8HW8qPf4rKCR6C4GFdQb8y3yKH_bypWGA3JltlGZ0vedtR6ADPk5sn5aPIY7hB6efB0Wb097cXT1oSxo9LEwwzKsCBODguMmpY6uu3ArHiNpf9jssSGUNPokhuA9tR2Yz7SzJj4GdbBbGGjXP0Ud_TqzsxWtedn9P7LbXq_bZhEMMoR3i74qQ8_iTxWxJ0mTxcp1b3_0PrIoM1wqhWiwJ9256Nlqw4AU5x7UvW4f_TW0cBtBBCkP9L3ud_3O1cKMFZEOaAJ0_a2UKSM70P0s87RA8G" request.Header.Add("cookie", cookie)
resp,_:=http.DefaultClient.Do(request) defer resp.Body.Close() if resp.StatusCode != http.StatusOK { fmt.Println("resp:",resp) return nil, fmt.Errorf("error:status code:%d", resp.StatusCode) } bodyReader := bufio.NewReader(resp.Body) e := determineEncoding(bodyReader) utf8Reader := transform.NewReader(bodyReader, e.NewDecoder()) return ioutil.ReadAll(utf8Reader) }
func determineEncoding(r *bufio.Reader) encoding.Encoding { bytes, err := r.Peek(1024) if err != nil { log.Printf("Ftcher error:%v", err) return unicode.UTF8 } e, _, _ := charset.DetermineEncoding(bytes, "") return e }
|