lundi 2 mars 2020

How to login in a website with captcha in go lang?

I want to login to a website that required captcha.

This is my code:

import (
"golang.org/x/net/publicsuffix"
"io/ioutil"
"log"
"net/http"
"net/http/cookiejar"
"net/url"
"fmt"
)

func main() {
_username := "usename"
_password := "password"
options := cookiejar.Options{
    PublicSuffixList: publicsuffix.List,
}
jar, err := cookiejar.New(&options)
if err != nil {
    log.Fatal(err)
}

client := http.Client{Jar: jar}
reader := bufio.NewReader(os.Stdin)
fmt.Print("Enter cpatcha: ")
_captcha, _ := reader.ReadString('\n')
fmt.Println(_captcha)

resp, err := client.PostForm("www.example.com/login", url.Values{
    "username": {_username},
    "password": {_password},
    "captcha":  {_captcha},
})
if err != nil {
    log.Fatal(err)
}

data, err := ioutil.ReadAll(resp.Body)
resp.Body.Close()
if err != nil {
    log.Fatal(err)
}
log.Println(string(data)) // print whole html of user profile data
 }

I want to get img source from (id="imgcpatcha") and save CAPTCHA image and then enter manually for getting cookie. But I cant get source from PostForm ex:

<img alt="Captcha" id="imgcpatcha" class="loginCpatcha" src="/Auth/Captcha" />



Aucun commentaire:

Enregistrer un commentaire