# -*- coding: utf-8 -*-
import requests, base64, re
from PIL import Image
from io import BytesIO
def logon():
loginUrl = 'http://############/login.do?method=enterbs' #登陆提交地址
imgUrl = 'http://############/form/digitalverify.jsp' #验证码获取地址
s = requests.session() #建立一个会话
res = s.get(imgUrl, stream=True) #获取验证码图片
im = Image.open(BytesIO(res.content))
im.show() #显示验证码
code = input() #人工输入正确的验证码
#用户名、密码进行转码(根据网站要求)
loginId = "############"
password = "############"
base64_loginId_utf_8 = base64.b64encode(loginId.encode('utf-8'))
base64_password_utf_8 = base64.b64encode(password.encode('utf-8'))
ID = re.findall(r'b\'(.*)\'', str(base64_loginId_utf_8)) #进过转码后会出现标志符号b',这里处理掉它
PWD = re.findall(r'b\'(.*)\'', str(base64_password_utf_
Python爬虫学习笔记一:模拟登录(人工输入简单验证码)
最新推荐文章于 2022-08-24 16:33:21 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)