How to pass registration form with captcha field using phantomjs?

On one of my pages, I ask the user for the credentials of another website so that I can visit the site with phantomjs in the background and get some data (because the site still doesn't have an 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 so he can enter the captcha code, but returning from the request the phantomjs session ended and if I run other phantomjs to login, then the captcha is no longer valid.

What's the best approach to do this? I see some sites do exactly that, but don't know how to do it.

By the way, I am using phantomjs in Django's view function.

+3


source to share


1 answer


It seems to me that you want a phantomjs instance that you start asynchronously from django on the first request. The phantomjs instance continues to run.

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

On the first request, you will stop and wait while phantomjs is on the intended page using captcha. If there is a captcha, return it to django and complete the first request.



On django server you have to map active users to phantomjs instance via port. On the next request with a resolved captcha, you are also exit

a phantom instance, but only if it was successful.

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

+2


source







All Articles