how to handle captcha through machanize module or any module

Jai jaiprakashsingh213 at gmail.com
Wed Dec 18 14:24:04 CET 2013


#/usr/bin/env python 

import mechanize, re
import cookielib
import cgi
import urllib2
from random import choice

def get_domain(url):
    return urlparse.urlparse(url).netloc


if __name__=="__main__":
   br = mechanize.Browser()
   cj = cookielib.LWPCookieJar()
   br.set_proxies({"http": "217.174.155.73:8080"})
   br.set_cookiejar(cj)
   br.addheaders = [('User-agent', 'Firefox')]
   br.set_handle_equiv(True)
   br.set_handle_gzip(True)
   br.set_handle_redirect(True)
   br.set_handle_referer(True)
   br.set_handle_robots(False)
   br.set_handle_refresh(False) # can sometimes hang without this
   url = "http://goarticles.com/"
   response = br.open(url)
   print response.info()
   link_list = []
   for link in br.links():
       match = re.search(r"register", str(link.url))
       if match: 
           link2 = (link.base_url[:-1]+link.url)
           if  link2 not in link_list:
               link_list.append(link2)
               print link2 

   response2 = br.open(link2)
   for form in br.forms():
       form.set_all_readonly(False)     
    
   br.form = list(br.forms())[1] # use when form is unnamed 
   for control in br.form.controls:
       if str(control.type) == "text" and str(control.name) =="email":
           br.form[str(control.name)]="jaiprakash at wisepromo.com"
       elif str(control.type)=="text":
           br.form[str(control.name)]="mybot"+control.name
       elif str(control.type) =="select":
           br.form[str(control.name)]=[str(control.items[1])]
       elif str(control.type) =="password":
           br.form[str(control.name)] = "mybotpassword213"
       elif str(control.type)=="checkbox":
       	   br.find_control(str(control.name)).items[0].selected=True
       elif re.search(r"captcha",str(control.name)):
           br.form[str(control.name)] = "mybotcaptcha"
       else:
          pass
       #elif str(control.type)=="submit":
      
   responce = br.submit()     
   print responce.info()
   #print responce.read()  





sir , i am very new to python i have just started to learn it , 

my aim is to  practice 
1)simple automatic form registration,
2)simple automatic vitrification
3)simple automatic loging

this site http://goarticles.com/register.html

sir i m referring  the mechanize  module

now i am stuck on two thing

1) how to automatically handling the captcha on this form
2) how to verify or  the filled form 

please help i have already gave 2 days on this  just i want some clue from ur side 



More information about the Python-list mailing list