如何使用phantomjs通过验证码字段传递登录表单? [英] How to pass login form with captcha field using phantomjs?

查看:241
本文介绍了如何使用phantomjs通过验证码字段传递登录表单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的一个页面中,我要求用户获取其他网站的凭据,以便我可以在后台使用phantomjs登录网站并获取一些数据(因为该网站还没有API或Oauth)。 / p>

我可以登录大部分时间,但有时服务器可疑,登录表单包含验证码字段。



我可以获取图像并将其返回给用户以输入验证码,但是从请求返回,phantomjs会话结束,如果我启动另一个phantomjs登录,则验证码不再有效。



最好的处理方法是什么?我看到一些网站正是这样做,但不知道如何。



BTW,我在Django视图功能中使用phantomjs。

解决方案

我想你需要一个phantomjs实例,您在第一个请求时从django异步运行。 phantomjs实例继续运行。



您可以使用网络服务器的phantomjs模块,在python启动后与目标phantomjs实例进行通信。



在第一个请求中,您将停止并等待phantomjs在与验证码的预期页面。如果有一个验证码,然后将其返回到django并完成第一个请求。



在django服务器中,您将通过端口将当前活动用户映射到phantomjs实例。在下一个请求与解决的验证码你也退出幻影实例,但只有成功。



可悲的是,我不清楚django请求管理是否显示一些代码。


In one of my pages, I ask user for credentials of another website, so that I can log in the website with phantomjs in the background and get some data (because the website still doesn't have API or Oauth).

I can log in most of the time, but sometimes the server got suspicious and the login form contains a captcha field.

I can get the image and return it to the user for him to enter captcha code, but returning from the request, the phantomjs session is ended, and if I start another phantomjs to log in, the captcha is no longer valid.

What is the best approach to handle this? I see some websites do exactly this but don't know how.

BTW, I am using phantomjs in a Django view function.

解决方案

I guess you need a phantomjs instance that you run asynchronously from django on the first request. The phantomjs instance continues running.

You can use the webserver module of phantomjs to communicate with the target phantomjs instance from python after it is started.

Inside the first request you stall and wait until the phantomjs is on the intended page with the captcha. If there is a captcha then return it to django and finish the first request.

In the django server you would map currently active users to phantomjs instance through the port. On the next request with the solved captcha you also exit the phantom instance, but only if it was successful.

Sadly, I don't know enough about django request management to you show some code.

这篇关于如何使用phantomjs通过验证码字段传递登录表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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