I'm using PhantomJS to login website and the captcha has to be inputed manually. How can I save the captcha image to disk, and then input the captcha by hand in PhantomJS console?
I'm using PhantomJS to login website and the captcha has to be inputed manually. How can I save the captcha image to disk, and then input the captcha by hand in PhantomJS console?
Share Improve this question edited Jan 20, 2019 at 15:16 Cœur 38.7k26 gold badges202 silver badges277 bronze badges asked May 8, 2013 at 23:53 aztackaztack 4,5947 gold badges35 silver badges57 bronze badges 4- Save the text .. not captcha rendered text – matzone Commented May 9, 2013 at 0:01
- 1 There's no text, only image. You have to recognize by yourself(by human) and then submit recognized text. – aztack Commented May 9, 2013 at 0:04
- Like this example, easy way make capctha from text in PHP .. – matzone Commented May 9, 2013 at 0:18
- 4 @matzone, sorry for my poor english.I thinik you didn't get it. I'm not making captcha. – aztack Commented May 9, 2013 at 0:26
2 Answers
Reset to default 19I had the same problem, just use the system module in combination with a page.render() and some argument passing to page.evaluate.
page.render('pagewithcatpcha.jpg');
page.injectJs('http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js');
var arg1 = consoleRead();
page.evaluate(function (arg1) {
$('.yourFormBox').val(arg1);
$('.yourForm').submit();
}, arg1);
function consoleRead() {
var system = require('system');
system.stdout.writeLine('CaptchaCode: ');
var line = system.stdin.readLine();
return line;
}
What you're asking sounds nearly impossible.
If I were desperate to do something like this I might consider the following approach:
- grab the capture, save to disk as image
- output to the console to tell user image is ready
- use window.setTimeout to wait 30 seconds
- user then edits a text file (e.g.
/tmp/code.txt
) with capture result - after 30 seconds the callback in window.setTimeout will read
/tmp/code.txt
It's not pretty. But I can't think of any other way off the top of my head.