headzoo / surf

Stateful programmatic web browsing in Go.
MIT License
1.48k stars 159 forks source link

How do I post the captcha info? #100

Open eminol opened 6 years ago

eminol commented 6 years ago

How do I post the captcha info?

Noy commented 6 years ago

The whole point of captchas are to prevent spam from programs that are made with things like surf. what captchas are you looking to complete? The only one i can think of doing with this are those simple ones that make you add two numbers

eminol commented 6 years ago

I want to show to user to captcha in website. User will enter information on captcha. I will make it automatically perform the actions on the site.

Below is the sample code. I'm entering captcha information. But it gives an error.

Best Regards.

//--------------------------------------------------------------------------------- package main

import ( "fmt" "github.com/headzoo/surf" "path/filepath" "os" "log" "github.com/headzoo/surf/browser" ) //--------------------------------------------------------------------------------- func main() { bow := surf.NewBrowser() err := bow.Open("https://medeczane.sgk.gov.tr/eczane") if err != nil { panic(err) } // Download the images on the page and write them to files. frms:=bow.Forms()

frm:=frms[1]
frm.Input("j_username", "zzzzzzz")
frm.Input("j_password", "ppppp")
for _, img:= range bow.Images() {
    if right(img.URL.Path,26)=="SayiUretenImageYeniServlet" {
        saveCaptcha(img)
        continue
    }
}
dz:="Login Captcha: "
fmt.Print(dz)
    //Input Captcha Inofrmation
fmt.Scanln(&dz)
frm.Input("guvenlikNumarasi",   dz)
frm.Submit()

println(bow.Body())

} //--------------------------------------------------------------------------------- func right (dz string, num int) string{ strLen :=len(dz) if strLen < num { return dz } return dz[strLen-num:] } //--------------------------------------------------------------------------------- func saveCaptcha(img *browser.Image) { fileName, := filepath.Abs(filepath.Dir(os.Args[0])) fileName = fileName + "/captcha.png" fs, err := os.Create(fileName) if err != nil { log.Printf( "Error create file '%s'.", fileName) panic(err) } defer fs.Close() //Resmi yükle , err = img.Download(fs) if err != nil { log.Printf( "Error create file '%s'.", fileName) panic(err) } } //---------------------------------------------------------------------------------

Joffcom commented 6 years ago

Have you tried printing the value of dz and returning the length to make sure there is no white spaces or new line characters?

Might be worth checking err for your inputs as well to make sure you are filling out the correct fields.

eminol commented 6 years ago

The captcha value you attach to the site changing during the download phase. It behaving like a different session.