import cookielib
import urllib
import urllib2
import re
import io
from PIL import Image
import pytesseract
print('loging info my ssfw')
cookie=cookielib.CookieJar()
opener=urllib2.build_opener(urllib2.HTTPCookieProcessor(cookie))
CaptchaUrl = "http://jwgl.nwsuaf.edu.cn/academic/getCaptcha.do"
picture = opener.open(CaptchaUrl).read()
local = open('e:/image1.jpg', 'wb')
local.write(picture)
local.close()
img=Image.open('e:/image1.jpg')
vcode = pytesseract.image_to_string(img)
print(vcode)
SecretCode=vcode
print(SecretCode)
loging_data=urllib.urlencode([
('j_username',"2014012528"),
('j_password',"3976966"),
('j_captcha',SecretCode)])
headers = {
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 '+
'(KHTML, like Gecko) Chrome/46.0.2490.71 Safari/537.36'
}
req=urllib2.Request(url='http://jwgl.nwsuaf.edu.cn/academic/j_acegi_security_check',
data=loging_data.encode(encoding='utf-8'),
headers=headers)
try:
result=opener.open(req)
except urllib2.HTTPError:
print("connect failed")
try:
result=opener.open('http://jwgl.nwsuaf.edu.cn/academic/manager/score/studentOwnScore.do?groupId=&moduleId=2021')
print(result.read().decode('utf-8'))
except urllib2.HTTPError:
print("error")