Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I post the captcha info? #100

Open
eminol opened this issue Mar 22, 2018 · 4 comments
Open

How do I post the captcha info? #100

eminol opened this issue Mar 22, 2018 · 4 comments

Comments

@eminol
Copy link

eminol commented Mar 22, 2018

How do I post the captcha info?

@Noy
Copy link
Contributor

Noy commented Mar 23, 2018

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
Copy link
Author

eminol commented Mar 25, 2018

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
Copy link

Joffcom commented Mar 26, 2018

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
Copy link
Author

eminol commented Mar 26, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants