forked from jShi-git/tplspider
/
test.go
103 lines (91 loc) · 2.17 KB
/
test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package main
import (
"flag"
"fmt"
"github.com/lealife/leacrawler"
"github.com/lxn/walk"
. "github.com/lxn/walk/declarative"
"os"
"os/exec"
"strings"
)
var a string
func getTemplate(url string, customPath string) {
customPath = strings.Replace(customPath, "\\", "\\\\", -1)
customPath = strings.Replace(customPath, "/", "\\\\", -1)
leacrawler.Fetch(url, customPath)
}
func main() {
var le, le2 *walk.LineEdit
var lb1, lb2 *walk.Label
var ck1 *walk.CheckBox
var mw *walk.MainWindow
copytext, _ := walk.Clipboard().Text()
updateIcon := func() {
mainIcon, err := walk.NewIconFromResource("101")
if err != nil {
// do some work
}
mw.SetIcon(mainIcon)
}
if err := (MainWindow{
AssignTo: &mw,
Title: "模板下载器",
MinSize: Size{400, 100},
Layout: VBox{},
Children: []Widget{
CheckBox{
AssignTo: &ck1,
Name: "cksnap",
Text: "带截图抓取",
Checked: false,
},
Label{
AssignTo: &lb1,
Text: "网址",
},
LineEdit{
AssignTo: &le,
Text: copytext,
},
Label{
AssignTo: &lb2,
Text: "保存目录",
},
LineEdit{
AssignTo: &le2,
Text: `D:\APMServ5.2.6\www\htdocs\down\tpls\`,
},
PushButton{
Text: "开始抓取",
OnClicked: func() {
fmt.Println(ck1.Checked())
if ck1.Checked() {
command := flag.String("cmd", "phantomjs", "Set the command.")
patharr := strings.Split(le2.Text(), "\\")
args := flag.String("args", "rasterize.js "+le.Text()+" "+le2.Text()+"\\"+patharr[len(patharr)-1]+".png", "Set the args. (separated by spaces)")
var argArray []string
if *args != "" {
argArray = strings.Split(*args, " ")
} else {
argArray = make([]string, 0)
}
flag.Parse()
cmd := exec.Command(*command, argArray...)
buf, err := cmd.Output()
if err != nil {
fmt.Fprintf(os.Stderr, "The command failed to perform: %s (Command: %s, Arguments: %s)", err, *command, *args)
return
}
fmt.Fprintf(os.Stdout, "Result: %s", buf)
}
getTemplate(le.Text(), le2.Text())
},
},
},
}.Create()); err != nil {
fmt.Println(err)
}
updateIcon()
mw.Run()
}