diff options
author | Dimitri Sokolyuk <demon@dim13.org> | 2015-08-15 16:15:40 +0200 |
---|---|---|
committer | Dimitri Sokolyuk <demon@dim13.org> | 2015-08-15 16:15:40 +0200 |
commit | dabffdc26b1fbeba192afbad9c5b74e72fa7bed4 (patch) | |
tree | 753c273710caf3a1eddb1cefc4cf41576b5ecb20 /href.go | |
parent | 525d80eda5e468785047e52e7441d6ce35e359fe (diff) |
Bypass nswf test on reddit
Diffstat (limited to 'href.go')
-rw-r--r-- | href.go | 24 |
1 files changed, 19 insertions, 5 deletions
@@ -4,6 +4,8 @@ import ( "errors" "log" "net/http" + "net/http/cookiejar" + "net/url" "strings" irc "github.com/fluffle/goirc/client" @@ -37,8 +39,20 @@ func findTitle(n *html.Node) (s string) { return "" } -func FetchTitle(url string) (string, error) { - resp, err := http.Get(url) +func FetchTitle(uri string) (string, error) { + client := &http.Client{} + if strings.Contains(uri, "reddit") { + u, _ := url.Parse(uri) + cookies := []*http.Cookie{ + &http.Cookie{ + Name: "over18", + Value: "1", + }, + } + client.Jar, _ = cookiejar.New(nil) + client.Jar.SetCookies(u, cookies) + } + resp, err := client.Get(uri) if err != nil { return "", err } @@ -75,9 +89,9 @@ func FetchTitle(url string) (string, error) { func ExtractLinks(conn *irc.Conn, line *irc.Line) { for _, v := range strings.Fields(line.Text()) { if strings.HasPrefix(v, "http") { - go func(url string) { - log.Println(line.Nick, url) - t, err := FetchTitle(url) + go func(uri string) { + log.Println(line.Nick, uri) + t, err := FetchTitle(uri) if err != nil { log.Println(err) } |