-
Notifications
You must be signed in to change notification settings - Fork 0
/
'
95 lines (79 loc) · 1.51 KB
/
'
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
package main
import (
"fmt"
"io"
"net/http"
"os"
"strings"
"sync"
)
func check(err error) {
if err != nil {
fmt.Println(err)
// panic(err)
}
}
func savePage(filename string, resp *http.Response) {
defer resp.Body.Close()
out, err := os.Create(fmt.Sprintf("./get/%s.html", filename))
if err != nil {
// panic?
}
defer out.Close()
io.Copy(out, resp.Body)
}
var ascii_lowercase = "abcdefghijklmnopqrstuvwxyz"
var lowercaseArray = strings.Split(ascii_lowercase, "")
func page(urlname string) {
resp, err := http.Get(
fmt.Sprintf("http://www.lazo.twmail.org/%s.html", urlname))
check(err)
defer resp.Body.Close()
if resp.StatusCode != 404 {
fmt.Println(urlname, resp.StatusCode)
savePage(urlname, resp)
}
}
func intToString(a int) string {
b := []int{}
for i := 1; i < a; i = i * 26 {
b = append([]int{i}, b...) // prepend trick
}
o := []byte{}
// make the original number
for _, b := range b {
o = append(o, 96+byte(a/b))
a = a % b
}
return string(o)
}
func start(urlname string) {
// for i := 0; i < 1; i++ {
fullName := fmt.Sprintf("%s%02d", urlname, 1)
// fmt.Println(fullName)
page(fullName)
// }
}
var wg sync.WaitGroup
func main() {
var going int = 0
for i := 10000; i < 1048576; i++ {
numToURL := ""
if i < 24 {
numToURL = lowercaseArray[i]
} else {
numToURL = intToString(i)
}
fmt.Println(i, numToURL)
wg.Add(1)
go func(numToURL string) {
defer wg.Done()
start(numToURL)
}(numToURL)
going++
if going == 100 {
wg.Wait()
going = 0
}
}
}