Advertisement
Guest User

Untitled

a guest
Jun 9th, 2017
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.99 KB | None | 0 0
  1. # Imagetyperz captcha API test
  2. # ------------------------------
  3. from imagetypersapi import ImageTypersAPI
  4. from time import sleep
  5.  
  6. # solve captcha
  7. def test_api():
  8. username = ''
  9. password = ''
  10.  
  11. ita = ImageTypersAPI(username, password) # init imagetyperz api obj
  12.  
  13. # check account balance
  14. # ---------------------------
  15. balance = ita.account_balance() # get account balance
  16. print 'Balance: {}'.format(balance) # print balance
  17.  
  18. # solve normal captcha
  19. print 'Waiting for captcha to be solved ...'
  20. # -----------------------------------------------------------------------------------------------
  21. captcha_text = ita.solve_captcha('captcha.jpg', case_sensitive = True) # solve captcha, with case sensitive arg True
  22. print 'Captcha text: {}'.format(captcha_text) # print captcha solved text
  23. # -----------------------------------------------------------------------------------------------
  24.  
  25. # solve recaptcha
  26. # ---------------
  27. # check: http://www.imagetyperz.com/Forms/recaptchaapi.aspx on how to get page_url and googlekey
  28. # -----------------------------------------------------------------------------------------------
  29. page_url = ''
  30. sitekey = ''
  31. captcha_id = ita.submit_recaptcha(page_url, sitekey) # submit captcha first, to get ID
  32.  
  33. # check if it's still in progress (waiting to be solved), every 10 seconds
  34. print 'Waiting for recaptcha to be solved ...'
  35. while ita.in_progress(): # while it's still in progress
  36. sleep(10) # sleep for 10 seconds and recheck
  37.  
  38. recaptcha_response = ita.retrieve_recaptcha(captcha_id) # captcha_id is optional, if not given, will use last captcha id submited
  39. print 'Recaptcha response: {}'.format(recaptcha_response) # print google response
  40.  
  41. # other examples
  42. # --------------------------------------------------------------------------------------
  43. # ita = ImageTyperzAPI('testingfor', 'testingfor', 60) # use a timeout of 60 seconds on requests
  44. # ita = ImageTyperzAPI('testingfor', 'testingfor', 60, 5) # use timeout and ref id
  45.  
  46. # submit recaptcha with proxy (checks API docs for more info)
  47. # captcha_id = ita.submit_recaptcha(page_url, sitekey, '127.0.0.1:1234', 'HTTP')
  48.  
  49. # print ita.captcha_id # get the last captcha solved id
  50. # print ita.captcha_text # get the last captcha solved text
  51.  
  52. # print ita.recaptcha_id # get last recaptcha solved id
  53. # print ita.recaptcha_response # get last recaptcha solved response
  54.  
  55. # print ita.set_captcha_bad(captcha_id) # set last captcha as bad, or set it by using ID
  56. # print ita.error # get the last error encountered
  57.  
  58. # main method
  59. def main():
  60. try:
  61. test_api() # test captcha API
  62. except Exception, ex:
  63. print '[!] Error occured: {}'.format(ex)
  64.  
  65. if __name__ == "__main__":
  66. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement