# -*- coding:utf-8 -*- import requests import random import pytesseract from bs4 import BeautifulSoup from PIL import Image import lxml x = requests.session() r = x.get('http://ecard.neu.edu.cn/SelfSearch/Login.aspx') # print(r.text) soup = BeautifulSoup(r.text, 'lxml') view_state = soup.find('input', id = '__VIEWSTATE')['value'] event_validation = soup.find('input', id = '__EVENTVALIDATION')['value'] # print(view_state) # print(event_validation) a = x.get('http://ecard.neu.edu.cn/SelfSearch/validateimage.ashx?' + str(random.uniform(0,1))) with open('a.jpg', 'wb') as file: file.write(a.content) i = Image.open('a.jpg') code = pytesseract.image_to_string(i) print(code) data = { '__EVENTVALIDATION':event_validation, '__VIEWSTATE':view_state, '__EVENTTARGET': 'btnLogin', 'txtUserName':'', # username 'txtPassword':'', # password 'txtVaildateCode':code, 'hfIsManager': 0 } b = x.post('http://ecard.neu.edu.cn/SelfSearch/Login.aspx', data = data) b.encoding = 'utf-8' if('验证码错误' in str(b.content)): print 'fail' else: print 'success' c = x.get('http://ecard.neu.edu.cn/SelfSearch/User/Home.aspx') print(c.text)
Python模拟登录东北大学校园卡主页
猜你喜欢
转载自blog.csdn.net/qq_32862515/article/details/78867800
今日推荐
周排行