有没有办法从键盘读取PhantomJS的用户输入? [英] Is there a way to read user input from keyboard for PhantomJS?

查看:62
本文介绍了有没有办法从键盘读取PhantomJS的用户输入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用PhantomJS登录网站,必须手动输入验证码。
如何将验证码图像保存到磁盘,然后在PhantomJS控制台中手动输入验证码?

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?

推荐答案

我有同样的问题,只需将系统模块与page.render()和一些参数传递给page.evaluate一起使用。

I 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;
}

这篇关于有没有办法从键盘读取PhantomJS的用户输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆