Captcha.py 950 B

123456789101112131415161718192021222324
  1. import random
  2. class Init_Captcha:
  3. def __init__(self):
  4. self.init_URL = "http://zxgk.court.gov.cn/shixin/captchaNew.do"
  5. def get_captchaId(self):
  6. chars = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A',
  7. 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
  8. 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y',
  9. 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k',
  10. 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
  11. 'x', 'y', 'z']
  12. nums = ""
  13. for i in range(32):
  14. ids = int(random.random() * 61)
  15. nums += chars[ids]
  16. return nums
  17. #返回一个验证码的URL
  18. def main(self):
  19. captchaId = self.get_captchaId()
  20. MyRandom = str(random.random())
  21. return self.init_URL + "?captchaId=" + captchaId + "&random=" + MyRandom, captchaId, MyRandom