Browse Source

通用方法信息模拟登陆方法

maxiaoshan 2 years ago
parent
commit
761d959369
3 changed files with 19 additions and 4 deletions
  1. 17 2
      src/spider/script.go
  2. 1 1
      src/spider/service.go
  3. 1 1
      src/web/templates/index.html

+ 17 - 2
src/spider/script.go

@@ -17,6 +17,7 @@ import (
 	gojs "gorunjs/client"
 	"io"
 	"io/ioutil"
+	login "login/client"
 	mu "mfw/util"
 	"mime/multipart"
 	"net/http"
@@ -51,7 +52,7 @@ type Script struct {
 }
 
 //加载文件
-func (s *Script) LoadScript(downloadnode, script string, isfile ...string) {
+func (s *Script) LoadScript(site *string, downloadnode, script string, isfile ...string) {
 	s.ScriptFile = script
 	options := lua.Options{
 		RegistrySize:        256 * 20,
@@ -714,6 +715,19 @@ func (s *Script) LoadScript(downloadnode, script string, isfile ...string) {
 		S.Push(lua.LString(contentHtml))
 		return 1
 	}))
+	//渲染页面下载
+	s.L.SetGlobal("getSimulateLoginInfo", s.L.NewFunction(func(S *lua.LState) int {
+		param := S.ToTable(-1)
+		header := S.ToTable(-2)
+		byteParam, _ := json.Marshal(util.TableToMap(param))
+		headerParam, _ := json.Marshal(util.TableToMap(header))
+		stype := S.ToString(-3) //login:登陆,get:获取cookie
+		qu.Debug(string(headerParam))
+		qu.Debug(string(byteParam))
+		cookie := login.GetSimulateLoginInfo(*site, stype, string(headerParam), string(byteParam))
+		S.Push(lua.LString(cookie))
+		return 1
+	}))
 	//辽宁省招标投标监管网
 	s.L.SetGlobal("multipartRequest", s.L.NewFunction(func(S *lua.LState) int {
 		yzm := S.ToString(-5)
@@ -791,7 +805,8 @@ func (s *Script) LoadScript(downloadnode, script string, isfile ...string) {
 //
 func (s *Script) Reload() {
 	s.L.Close()
-	s.LoadScript("", s.ScriptFile)
+	site := ""
+	s.LoadScript(&site, "", s.ScriptFile)
 }
 
 //unicode转码

+ 1 - 1
src/spider/service.go

@@ -231,7 +231,7 @@ func ReplaceModel(script string, comm []interface{}, model map[string]interface{
 func CreateSpider(downloadnode, script string, isfile ...string) *Spider {
 	defer mu.Catch()
 	sp := &Spider{}
-	sp.LoadScript(downloadnode, script, isfile...)
+	sp.LoadScript(&sp.Name, downloadnode, script, isfile...)
 	sp.Code = sp.GetVar("spiderCode")
 	sp.SCode = sp.Code
 	sp.Name = sp.GetVar("spiderName")

+ 1 - 1
src/web/templates/index.html

@@ -365,7 +365,7 @@ $(function(){
 				});
 			}}
 		],
-		"order": [[1,"desc"]],
+
 		"processing":true,
 		"serverSide": true,
 		"searching": true,