]> 127.0.0.1 Git - part/.git/commitdiff
64
authorqydysky <qydysky@foxmail.com>
Tue, 22 Sep 2020 02:42:13 +0000 (10:42 +0800)
committerqydysky <qydysky@foxmail.com>
Tue, 22 Sep 2020 02:42:13 +0000 (10:42 +0800)
Get.go [new file with mode: 0644]
Reqf.go

diff --git a/Get.go b/Get.go
new file mode 100644 (file)
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 1302a7a7e5125e927e492b286a2ca4f5aa35dcfc..51ede6f69c8e8eb560f5bc82fdf6986ea44cccd5 100644 (file)
--- 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)}