maxiaoshan 3 سال پیش
والد
کامیت
5cb0644062
7فایلهای تغییر یافته به همراه57 افزوده شده و 6 حذف شده
  1. 1 0
      src/config.json
  2. 3 1
      src/main.go
  3. 2 2
      src/spider/msgservice.go
  4. 8 0
      src/spider/script.go
  5. 25 2
      src/spider/spider.go
  6. 1 1
      src/spider/store.go
  7. 17 0
      src/spider/util.go

+ 1 - 0
src/config.json

@@ -21,6 +21,7 @@
     "testdir": "res/spider_a_zgzbtbggfwpt_zgysgg2.lua",
     "redistype": "0",
     "redisservers": "title_repeat_judgement=192.168.3.207:1679,title_repeat_fulljudgement=192.168.3.207:1679,title_repeat_listpagehref=192.168.3.207:1679",
+    "serveraddress": "127.0.0.1:8030",
     "word":{
     	"keyword":"(抽签|中标|招标|成交|合同|中标候选人|资格预审|拟建|邀请|询价|比选|议价|竞价|磋商|采购|招投标|答疑|变更公告|更正公告|竞争性谈判|竞谈|意见征询|澄清|单一来源|流标|废标|验收公告|中止|终止|违规|处罚|征集公告|开标结果|评审结果|监理|招租|租赁|评判结果|项目|遴选|补遗|竞标|征求意见|标段|定点结果|项目评审公示|采购项目违规|采购活动中违规|项目行政处罚|采购行政处罚|项目审批公示)",
     	"notkeyword":"(招聘|拍卖|出租|出让|使用权|资产)"

+ 3 - 1
src/main.go

@@ -1,6 +1,7 @@
 package main
 
 import (
+	codegrpc "analysiscode"
 	"fmt"
 	"io/ioutil"
 	mgo "mongodb"
@@ -40,7 +41,8 @@ func init() {
 	//启动消息服务
 	spider.InitMsgClient(Config.Msgserveraddr, Config.Msgname)
 	spider.InitMsgClientFile(Config.MsgserveraddrFile, Config.Msgname+"file")
-
+	//验证码识别client
+	codegrpc.InitCodeGrpcClient()
 	//初始化网络存储服务
 	OssInit(
 		qu.ObjToString(Config.OssInfo["ossEndpoint"]),

+ 2 - 2
src/spider/msgservice.go

@@ -290,7 +290,7 @@ func SaveObj(event int, checkAtrr string, data map[string]interface{}, saveredis
 			}
 			//保存服务未接收成功的数据会存入data_bak中,确保数据不丢失依赖补发程序
 			if id != "" {
-				util.PutRedis("title_repeat_judgement", 0, "url_repeat_"+href, href, 3600*24*30)
+				util.PutRedis("title_repeat_judgement", 0, "url_repeat_"+href, href, 3600*24*365)
 				if !flag { //保存服务发送成功
 					//全量(判断是否已存在防止覆盖id)
 					isExist, _ := util.ExistRedis("title_repeat_fulljudgement", db, hashHref)
@@ -306,7 +306,7 @@ func SaveObj(event int, checkAtrr string, data map[string]interface{}, saveredis
 		// 	if len(href) > 5 && saveredis { //有效数据
 		// 		db := HexToBigIntMod(href) //根据href的哈希值选择Redis的db
 		// 		//增量
-		// 		util.PutRedis("title_repeat_judgement", 0, "url_repeat_"+href, href, 3600*24*30)
+		// 		util.PutRedis("title_repeat_judgement", 0, "url_repeat_"+href, href, 3600*24*365)
 		// 		//全量(判断是否已存在防止覆盖id)
 		// 		isExist, _ := util.ExistRedis("title_repeat_fulljudgement", db, "url_repeat_"+href)
 		// 		if !isExist {

+ 8 - 0
src/spider/script.go

@@ -7,6 +7,7 @@ LUA中公共的方法需要抽出来,主脚本文件加载LUA公共文件
 package spider
 
 import (
+	codegrpc "analysiscode"
 	"bytes"
 	"compress/gzip"
 	"crypto/aes"
@@ -781,6 +782,13 @@ func (s *Script) LoadScript(code, script_file string, newstate bool) string {
 		S.Push(lua.LString(decimalNum.String()))
 		return 1
 	}))
+	//获取验证码
+	s.L.SetGlobal("getCodeByPath", s.L.NewFunction(func(S *lua.LState) int {
+		path := S.ToString(-1)
+		code := codegrpc.GetCodeByPath(path)
+		S.Push(lua.LString(code))
+		return 1
+	}))
 	return ""
 }
 func dealHref(pageListUrl, href string) string {

+ 25 - 2
src/spider/spider.go

@@ -64,6 +64,7 @@ var UpdataMgoCache = make(chan []map[string]interface{}, 1000) //更新要重下
 var SP = make(chan bool, 5)
 var TimeChan = make(chan bool, 1)
 var Reg = regexp.MustCompile(`(http|https)://([\w]+\.)+[\w]+(/?)`)
+var DelaySites map[string]int //延迟采集站点集合
 
 //高性能模式定时采集三级页信息
 func DetailData() {
@@ -89,6 +90,7 @@ func DownloadHighDetail(code string) {
 	for {
 		//logger.Info("爬虫代码:", s.Code, "已下架:", s.Stop)
 		//if !s.Stop { //爬虫是运行状态
+		//TODO 延迟采集还未添加
 		/*
 			1、每轮开始先查询当天下载的数据
 			2、本次查询无数据依次向前推一天查询数据(暂定50条数据)
@@ -136,6 +138,28 @@ func DownloadHighDetail(code string) {
 					}()
 					_id := tmp["_id"]
 					query := map[string]interface{}{"_id": _id}
+					href := qu.ObjToString(tmp["href"])
+					//由于目前列表页redis判重是href+code可能导致同一条href有多条不同code采集的数据存在
+					//为了避免重复下载,进行增量redis判重
+					isExist, _ := util.ExistRedis("title_repeat_judgement", 0, "url_repeat_"+href)
+					if isExist {
+						set := map[string]interface{}{"$set": map[string]interface{}{"state": 1, "exist": true}} //已存在state置为1
+						MgoS.Update("spider_highlistdata", query, set, false, false)
+						return
+					}
+					// if isEsRepeat { //竞品数据es title判重
+					// 	title := qu.ObjToString(tmp["title"])
+					// 	eTime := time.Now().Unix()
+					// 	sTime := eTime - int64(7*86400)
+					// 	esQuery := `{"query": {"filtered": {"filter": {"bool": {"must": [{"range": {"comeintime": {"gte": "` + fmt.Sprint(sTime) + `","lte": "` + fmt.Sprint(eTime) + `"}}}]}},"query": {"bool": {"must": [{"multi_match": {"query": "` + title + `","type": "phrase","fields": ["title"]}}]}}}}}`
+					// 	count := Es.Count(EsIndex, EsType, esQuery)
+					// 	if count > 0 { //es中含本title数据,不再采集,更新list表数据状态
+					// 		set := map[string]interface{}{"$set": map[string]interface{}{"state": 1, "exist": true}} //已存在state置为1
+					// 		Mgo.Update("spider_highlistdata", query, set, false, false)
+					// 		util.PutRedis("title_repeat_judgement", 0, "url_repeat_"+href, href, 3600*24*365)
+					// 		continue
+					// 	}
+					// }
 					competehref := qu.ObjToString(tmp["competehref"])
 					if competehref != "" { //验证三方网站数据剑鱼是否已采集
 						title := qu.ObjToString(tmp["title"])
@@ -150,7 +174,6 @@ func DownloadHighDetail(code string) {
 					success := true //数据是否下载成功的标志
 					delete(tmp, "_id")
 					delete(tmp, "times")
-					href := qu.ObjToString(tmp["href"])
 					data := map[string]interface{}{}
 					var err interface{}
 					for k, v := range tmp {
@@ -177,7 +200,7 @@ func DownloadHighDetail(code string) {
 					} else if tmphref := qu.ObjToString(data["href"]); tmphref != href { //三级页href替换导致前后href不同
 						log.Println("beforeHref:", href, "afterHref:", href)
 						//增量
-						util.PutRedis("title_repeat_judgement", 0, "url_repeat_"+href, href, 3600*24*30)
+						util.PutRedis("title_repeat_judgement", 0, "url_repeat_"+href, href, 3600*24*365)
 						//全量
 						db := HexToBigIntMod(tmphref)
 						hashHref := HexText(href)

+ 1 - 1
src/spider/store.go

@@ -81,7 +81,7 @@ func Store(mode, event int, c, coverAttr string, data map[string]interface{}, fl
 			db := HexToBigIntMod(href) //根据href的哈希值选择Redis的db
 			hashHref := HexText(href)
 			//增量
-			lu.PutRedis("title_repeat_judgement", 0, "url_repeat_"+href, href, 3600*24*30)
+			lu.PutRedis("title_repeat_judgement", 0, "url_repeat_"+href, href, 3600*24*365)
 			//全量
 			isExist, _ := lu.ExistRedis("title_repeat_fulljudgement", db, hashHref)
 			if !isExist {

+ 17 - 0
src/spider/util.go

@@ -0,0 +1,17 @@
+package spider
+
+import (
+	qu "qfw/util"
+)
+
+//初始化延迟采集站点集合
+func InitOther() {
+	defer qu.Catch()
+	DelaySites = map[string]int{}
+	list, _ := MgoS.Find("spider_compete", nil, nil, nil, false, -1, -1)
+	for _, l := range *list {
+		site := qu.ObjToString(l["site"])
+		delayTime := qu.IntAll(l["delaytime"])
+		DelaySites[site] = delayTime
+	}
+}