From 39a1b17b5fa0ac742284db8ca45bcc8cf7c1a55d Mon Sep 17 00:00:00 2001 From: qydysky Date: Tue, 22 Sep 2020 10:42:13 +0800 Subject: [PATCH] 64 --- Get.go | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ Reqf.go | 3 ++- 2 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 Get.go diff --git a/Get.go b/Get.go new file mode 100644 index 0000000..0924d3a --- /dev/null +++ b/Get.go @@ -0,0 +1,55 @@ +package part + +import ( + "strings" + "errors" +) + +type get struct { + body []byte + + RS string + Err error +} + +func Get(r Rval) (o *get){ + o = new(get) + + if r.Url == "" {o.Err = errors.New("url == nil");return} + + R := Req() + o.Err = R.Reqf(r) + (*o).body = R.Respon + + return +} + +func (i *get) S(stratS,endS string, startI,lenI int) (o *get) { + o = i + + if stratS == "" && startI == 0 {o.Err = errors.New("no symbol to start");return} + if endS == "" && lenI == 0 {o.Err = errors.New("no symbol to stop");return} + s := string(o.body) + + var ts,te int + + if stratS != "" { + if tmp := strings.Index(s, stratS);tmp != -1{ts = tmp + len(stratS)} + } else if startI != 0 { + if startI < len(s){ts = startI} + } + + if ts == 0 {o.Err = errors.New("no start symbol in " + s);return} + + if endS != "" { + if tmp := strings.Index(s[ts:], endS);tmp != -1{te = ts + tmp} + } else if lenI != 0 { + if startI + lenI < len(s){te = startI + lenI} + } + + if te == 0 {o.Err = errors.New("no stop symbol in " + s);return} + + o.RS = s[ts:te] + o.Err = nil + return +} diff --git a/Reqf.go b/Reqf.go index 1302a7a..51ede6f 100644 --- a/Reqf.go +++ b/Reqf.go @@ -110,11 +110,12 @@ func (this *req) Reqf_1(val Rval) (error) { if len(PostStr) > 0 { Method = "POST"; body = strings.NewReader(PostStr); - if Connection == "" {Connection = "Keep-Alive"} if ContentType == "" {ContentType = "application/x-www-form-urlencoded"} } req,_ := http.NewRequest(Method, Url, body) + if Accept==""{Accept = `text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8`} + if Connection==""{Connection = "keep-alive"} if Cookie!=""{req.Header.Add("Cookie",Cookie)} if Referer!=""{req.Header.Add("Referer",Referer)} -- 2.39.2