-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscrape.go
61 lines (48 loc) · 1.24 KB
/
scrape.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
package main
import (
"fmt"
"net/http"
"os"
"sync"
)
// The instagram base URL
const baseURL = "https://instagram.com/"
// Check if the name is available and if so send it to the channel 'validNames'
func checkName(name string, validNames chan string, waitgroup *sync.WaitGroup) {
resp, err := http.Get(baseURL + name)
if err != nil {
fmt.Printf("[*] Response error on: %s\n", baseURL+name)
return
}
defer resp.Body.Close()
defer waitgroup.Done()
fmt.Printf("[*] Trying: %s\t Status: %d\n", name, resp.StatusCode)
switch resp.StatusCode {
// Name is available
case 404:
validNames <- name
// Name is taken
case 200:
break
// We made too many requests
case 429:
// TODO wait automatically
fmt.Println("[*] Made too many requests, try again later...")
os.Exit(1)
// Instagram down omg
default:
fmt.Printf("[*] Unhandled Status: %d for %s", resp.StatusCode, name)
return
}
}
func searchForPattern(p Pattern, opts PatternOptions, validNames chan string, wg *sync.WaitGroup) {
// Generate all usernames for the specific pattern
usernames := generateUserNames(p, opts)
// Check availability of every name
for _, name := range usernames {
wg.Add(1)
go checkName(name, validNames, wg)
}
wg.Wait()
close(validNames)
}