maxiaoshan 2 years ago
parent
commit
395cd6d51a
3 changed files with 13 additions and 0 deletions
  1. 1 0
      src/config.json
  2. 3 0
      src/main.go
  3. 9 0
      src/spider/script.go

+ 1 - 0
src/config.json

@@ -26,6 +26,7 @@
     "testdir": "res/spider_a_zgzbtbggfwpt_zgysgg2.lua",
     "redistype": "0",
     "serveraddress": "127.0.0.1:8030",
+    "jsserveraddress":  "127.0.0.1:8031",
     "redisclusteraddrs": [
         "192.168.3.207:2179",
         "192.168.3.166:2379"

+ 3 - 0
src/main.go

@@ -3,6 +3,7 @@ package main
 import (
 	codegrpc "analysiscode/client"
 	"fmt"
+	gojs "gorunjs/client"
 	"io/ioutil"
 	mgo "mongodb"
 	"os"
@@ -64,6 +65,8 @@ func init() {
 	spider.InitMsgClientFile(Config.MsgserveraddrFile, Config.Msgname+"file")
 	//验证码识别client
 	codegrpc.InitCodeGrpcClient()
+	//go执行js服务
+	gojs.InitGoRunJsClient()
 	//初始化网络存储服务
 	OssInit(
 		qu.ObjToString(Config.OssInfo["ossEndpoint"]),

+ 9 - 0
src/spider/script.go

@@ -13,6 +13,7 @@ import (
 	"crypto/aes"
 	"encoding/base64"
 	"encoding/json"
+	gojs "gorunjs/client"
 	"io/ioutil"
 	mu "mfw/util"
 	"net/http"
@@ -827,6 +828,14 @@ func (s *Script) LoadScript(site *string, code, script_file string, newstate boo
 		S.Push(lua.LString(respCookie))
 		return 3
 	}))
+	s.L.SetGlobal("goRunJs", s.L.NewFunction(func(S *lua.LState) int {
+		param := S.ToString(-2) //list or detail
+		step := S.ToString(-1)  //参数
+		result := gojs.GoRunJsGetResult(s.SCode, param, step)
+		qu.Debug("Go Run Js Result:", param, step, result)
+		S.Push(lua.LString(result))
+		return 1
+	}))
 	s.L.SetGlobal("newDownloadFile", s.L.NewFunction(func(S *lua.LState) int {
 		cookie := S.ToString(-1)
 		head := S.ToTable(-2)