-
Notifications
You must be signed in to change notification settings - Fork 0
/
testGetHTML.go
71 lines (62 loc) · 1.56 KB
/
testGetHTML.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
package main
import (
"fmt"
p "github.com/benbjohnson/phantomjs"
"os"
"os/exec"
"log"
"time"
)
var (
urls []string
)
func init() {
for i := 2; i < 100; i++{
urls = append(urls, fmt.Sprintf("http://w3.afulyu.info/pw/thread.php?fid=22&page=", string(i)))
urls = append(urls, fmt.Sprintf("http://ac88.info/bt/thread.php?fid=4&page=", string(i)))
urls = append(urls, fmt.Sprintf("http://w3.afulyu.info/pw/thread.php?fid=5&page=", string(i)))
urls = append(urls, fmt.Sprintf("http://ac88.info/bt/thread.php?fid=16&page=", string(i)))
}
}
func main() {
usePhantomjs()
}
func useCurl() {
var output []byte
var err error
// 格式化获得进程列表,还有LIST, TABLE
cmd := exec.Command("curl", "http://w3.afulyu.info/pw/thread.php?fid=22&page=5")
if output, err = cmd.Output(); err != nil {
fmt.Print(err)
os.Exit(0)
}
fmt.Println(string(output))
}
func usePhantomjs() {
start := time.Now()
errFile,err:=os.OpenFile("errors.log",os.O_CREATE|os.O_WRONLY|os.O_APPEND,0666)
if err!=nil{
log.Fatalln("打开日志文件失败:",err)
}
Info := log.New(errFile,"Info:",log.Ldate | log.Ltime | log.Lshortfile)
if err := p.DefaultProcess.Open(); err != nil {
fmt.Println(err)
os.Exit(1)
}
defer p.DefaultProcess.Close()
page, err := p.CreateWebPage()
if err != nil {
fmt.Println(err)
}
defer page.Close()
for _, url := range urls{
if err := page.Open(url); err != nil {
fmt.Println(err)
} else {
fmt.Println(page.Content())
Info.Println(page.Content())
}
}
elapsed := time.Since(start)
fmt.Printf("coast time:", elapsed )
}