|
@@ -56,7 +56,10 @@ type Step2 struct {
|
|
DateFormat string
|
|
DateFormat string
|
|
Expert string
|
|
Expert string
|
|
Types int
|
|
Types int
|
|
- Chrome string
|
|
|
|
|
|
+ //chromedp相关
|
|
|
|
+ Chrome string
|
|
|
|
+ RangeChrome string
|
|
|
|
+ RangeTimes int
|
|
}
|
|
}
|
|
|
|
|
|
type Step3 struct {
|
|
type Step3 struct {
|
|
@@ -350,8 +353,9 @@ func (f *Front) SaveStep() {
|
|
f.Step3.ContentChooser,
|
|
f.Step3.ContentChooser,
|
|
f.Step3.ElementChooser,
|
|
f.Step3.ElementChooser,
|
|
}
|
|
}
|
|
- param_list_chrome, param_content_chrome := []sp.ChromeActions{}, []sp.ChromeActions{}
|
|
|
|
|
|
+ param_list_chrome, param_list_rangechrome, param_content_chrome := []sp.ChromeActions{}, []sp.ChromeActions{}, []sp.ChromeActions{}
|
|
json.Unmarshal([]byte(f.Step2.Chrome), ¶m_list_chrome)
|
|
json.Unmarshal([]byte(f.Step2.Chrome), ¶m_list_chrome)
|
|
|
|
+ json.Unmarshal([]byte(f.Step2.RangeChrome), ¶m_list_rangechrome)
|
|
json.Unmarshal([]byte(f.Step3.Chrome), ¶m_content_chrome)
|
|
json.Unmarshal([]byte(f.Step3.Chrome), ¶m_content_chrome)
|
|
param := map[string]interface{}{}
|
|
param := map[string]interface{}{}
|
|
common[4] = 1
|
|
common[4] = 1
|
|
@@ -362,6 +366,8 @@ func (f *Front) SaveStep() {
|
|
param["param_time"] = ptime
|
|
param["param_time"] = ptime
|
|
param["param_list"] = list
|
|
param["param_list"] = list
|
|
param["param_list_chrome"] = param_list_chrome
|
|
param["param_list_chrome"] = param_list_chrome
|
|
|
|
+ param["param_list_rangechrome"] = param_list_rangechrome
|
|
|
|
+ param["param_list_rangetimes"] = f.Step2.RangeTimes
|
|
param["param_content_chrome"] = param_content_chrome
|
|
param["param_content_chrome"] = param_content_chrome
|
|
param["param_content"] = content
|
|
param["param_content"] = content
|
|
param["type_time"] = f.Step1.Types
|
|
param["type_time"] = f.Step1.Types
|
|
@@ -372,6 +378,7 @@ func (f *Front) SaveStep() {
|
|
param["str_time"] = f.Step1.Expert
|
|
param["str_time"] = f.Step1.Expert
|
|
param["str_list"] = f.Step2.Expert
|
|
param["str_list"] = f.Step2.Expert
|
|
param["str_list_chrome"] = f.Step2.Chrome
|
|
param["str_list_chrome"] = f.Step2.Chrome
|
|
|
|
+ param["str_list_rangechrome"] = f.Step2.RangeChrome
|
|
param["str_content_chrome"] = f.Step3.Chrome
|
|
param["str_content_chrome"] = f.Step3.Chrome
|
|
param["str_content"] = f.Step3.Expert
|
|
param["str_content"] = f.Step3.Expert
|
|
param["comeintime"] = comeintime
|
|
param["comeintime"] = comeintime
|
|
@@ -440,7 +447,7 @@ func (f *Front) SaveStep() {
|
|
param["spidermovevent"] = movevent
|
|
param["spidermovevent"] = movevent
|
|
}
|
|
}
|
|
//开发人员修改爬虫节点后,在审核人员上架时,要在原来的节点下架,临时记录要下架的节点downevent
|
|
//开发人员修改爬虫节点后,在审核人员上架时,要在原来的节点下架,临时记录要下架的节点downevent
|
|
- if event := qu.IntAll((*one)["event"]); event != tmpEvent && event != 7000 {
|
|
|
|
|
|
+ if event := qu.IntAll((*one)["event"]); event != tmpEvent && (*one)["downevent"] == nil {
|
|
param["downevent"] = event
|
|
param["downevent"] = event
|
|
}
|
|
}
|
|
//三级页复制
|
|
//三级页复制
|
|
@@ -448,7 +455,7 @@ func (f *Front) SaveStep() {
|
|
param["iscopycontent"] = f.StepRe3.Checked
|
|
param["iscopycontent"] = f.StepRe3.Checked
|
|
//
|
|
//
|
|
param["listisfilter"] = ListFilterReg.MatchString(f.Step2.Expert) //列表页校验是否含“--关键词过滤”
|
|
param["listisfilter"] = ListFilterReg.MatchString(f.Step2.Expert) //列表页校验是否含“--关键词过滤”
|
|
- checkLua := LuaTextCheck(infoformat, param, param_list_chrome, param_content_chrome, msgResult)
|
|
|
|
|
|
+ checkLua := LuaTextCheck(infoformat, param, param_list_chrome, param_list_rangechrome, param_content_chrome, msgResult)
|
|
//checkLua := LuaTextCheck(f.Base.SpiderCode, f.Step2.Expert, f.Step3.Expert, f.Step2.Types, infoformat, model, msgResult)
|
|
//checkLua := LuaTextCheck(f.Base.SpiderCode, f.Step2.Expert, f.Step3.Expert, f.Step2.Types, infoformat, model, msgResult)
|
|
if !checkLua {
|
|
if !checkLua {
|
|
issave := spider.SaveSpider(code, param) //保存脚本
|
|
issave := spider.SaveSpider(code, param) //保存脚本
|
|
@@ -633,7 +640,7 @@ func LuaTextCheck(code, list, detail string, type_list, infoformat int, model ma
|
|
msgResult["err"] = errmsg
|
|
msgResult["err"] = errmsg
|
|
return errmsg != ""
|
|
return errmsg != ""
|
|
}*/
|
|
}*/
|
|
-func LuaTextCheck(infoformat int, param map[string]interface{}, param_list_chrome, param_content_chrome []sp.ChromeActions, msgResult map[string]string) bool {
|
|
|
|
|
|
+func LuaTextCheck(infoformat int, param map[string]interface{}, param_list_chrome, param_list_rangechrome, param_content_chrome []sp.ChromeActions, msgResult map[string]string) bool {
|
|
code := qu.ObjToString(param["code"])
|
|
code := qu.ObjToString(param["code"])
|
|
list := qu.ObjToString(param["str_list"])
|
|
list := qu.ObjToString(param["str_list"])
|
|
detail := qu.ObjToString(param["str_content"])
|
|
detail := qu.ObjToString(param["str_content"])
|
|
@@ -655,7 +662,14 @@ func LuaTextCheck(infoformat int, param map[string]interface{}, param_list_chrom
|
|
if strings.Contains(list, "downloadByChrome") { //chrome下载方法动作参数判断
|
|
if strings.Contains(list, "downloadByChrome") { //chrome下载方法动作参数判断
|
|
for _, act := range param_list_chrome {
|
|
for _, act := range param_list_chrome {
|
|
if act.Action != "changeip" && act.Param == "" {
|
|
if act.Action != "changeip" && act.Param == "" {
|
|
- errmsg += "列表页chrome模式'" + act.Action + "'动作未填写参数,填写后注意Ctrl+F10重新插入代码;"
|
|
|
|
|
|
+ errmsg += "列表页chrome模式'" + act.Action + "'基础动作未填写参数,填写后注意Ctrl+F10重新插入代码;"
|
|
|
|
+ break
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ for _, act := range param_list_rangechrome {
|
|
|
|
+ if act.Action != "changeip" && act.Param == "" {
|
|
|
|
+ errmsg += "列表页chrome模式'" + act.Action + "'循环动作未填写参数,填写后注意Ctrl+F10重新插入代码;"
|
|
|
|
+ break
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -768,18 +782,43 @@ func (f *Front) RunStep() {
|
|
}
|
|
}
|
|
case "Step2": //list
|
|
case "Step2": //list
|
|
if imodal == 2 { //chromedp测试
|
|
if imodal == 2 { //chromedp测试
|
|
- chromeActions := []sp.ChromeActions{}
|
|
|
|
- var result []interface{}
|
|
|
|
- if json.Unmarshal([]byte(f.Step2.Chrome), &chromeActions) == nil {
|
|
|
|
|
|
+ //基础动作
|
|
|
|
+ if f.Step2.Chrome != "" {
|
|
|
|
+ chromeActions := []sp.ChromeActions{}
|
|
|
|
+ rangeChromeActions := []sp.ChromeActions{}
|
|
|
|
+ var result []interface{}
|
|
|
|
+ //格式化基础动作
|
|
|
|
+ if json.Unmarshal([]byte(f.Step2.Chrome), &chromeActions) != nil {
|
|
|
|
+ f.ServeJson("chrome基础动作格式化错误")
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ //格式化循环动作
|
|
|
|
+ if f.Step2.RangeChrome != "" {
|
|
|
|
+ if json.Unmarshal([]byte(f.Step2.RangeChrome), &rangeChromeActions) != nil {
|
|
|
|
+ f.ServeJson("chrome循环动作格式化错误")
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //拼装基础和循环动作
|
|
|
|
+ if len(rangeChromeActions) > 0 && f.Step2.RangeTimes > 0 {
|
|
|
|
+ for times := 1; times <= f.Step2.RangeTimes; times++ {
|
|
|
|
+ chromeActions = append(chromeActions, rangeChromeActions...)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
chromeTask := sp.ChromeTask{
|
|
chromeTask := sp.ChromeTask{
|
|
TimeOut: 120, //测试默认两分钟
|
|
TimeOut: 120, //测试默认两分钟
|
|
Actions: chromeActions,
|
|
Actions: chromeActions,
|
|
}
|
|
}
|
|
result = spider.DownloadByChrome(downloadnode, "", chromeTask, 150)
|
|
result = spider.DownloadByChrome(downloadnode, "", chromeTask, 150)
|
|
|
|
+ resultMap := map[int]interface{}{}
|
|
|
|
+ for i, r := range result {
|
|
|
|
+ resultMap[i] = r
|
|
|
|
+ }
|
|
|
|
+ f.ServeJson(resultMap)
|
|
} else {
|
|
} else {
|
|
- result = append(result, "chrome task json 格式化错误")
|
|
|
|
|
|
+ f.ServeJson("未进行动作编排")
|
|
}
|
|
}
|
|
- f.ServeJson(result)
|
|
|
|
|
|
+
|
|
} else {
|
|
} else {
|
|
addrs := strings.Split(f.Step2.Listadds, "\n")
|
|
addrs := strings.Split(f.Step2.Listadds, "\n")
|
|
if len(addrs) > 0 {
|
|
if len(addrs) > 0 {
|
|
@@ -834,7 +873,11 @@ func (f *Front) RunStep() {
|
|
} else {
|
|
} else {
|
|
result = append(result, "chrome task json 格式化错误")
|
|
result = append(result, "chrome task json 格式化错误")
|
|
}
|
|
}
|
|
- f.ServeJson(result)
|
|
|
|
|
|
+ resultMap := map[int]interface{}{}
|
|
|
|
+ for i, r := range result {
|
|
|
|
+ resultMap[i] = r
|
|
|
|
+ }
|
|
|
|
+ f.ServeJson(resultMap)
|
|
} else {
|
|
} else {
|
|
content := []interface{}{
|
|
content := []interface{}{
|
|
f.Step3.ContentChooser,
|
|
f.Step3.ContentChooser,
|
|
@@ -1405,8 +1448,9 @@ func UpStateAndUpSpider(code, id, reason, username string, state int) (bool, err
|
|
if upresult && err == nil {
|
|
if upresult && err == nil {
|
|
unset = map[string]interface{}{"downevent": ""}
|
|
unset = map[string]interface{}{"downevent": ""}
|
|
}
|
|
}
|
|
|
|
+ } else {
|
|
|
|
+ upresult, err = spider.UpdateSpiderByCodeState(code, "6", event)
|
|
}
|
|
}
|
|
- upresult, err = spider.UpdateSpiderByCodeState(code, "6", event)
|
|
|
|
qu.Debug("下架:", upresult, code)
|
|
qu.Debug("下架:", upresult, code)
|
|
if upresult && err == nil {
|
|
if upresult && err == nil {
|
|
upresult, err = spider.UpdateSpiderByCodeState(code, fmt.Sprint(state), event)
|
|
upresult, err = spider.UpdateSpiderByCodeState(code, fmt.Sprint(state), event)
|