import requests
from PIL import Image
from io import BytesIO
# 设置会话,保持会话状态
s = requests.Session()
# 发送获取验证码的请求
response = s.get('https://kyfw.12306.cn/passport/captcha/captcha-image?login_site=E&module=login&rand=sjrand')
# 将返回的bytes类型数据转成Image对象
image = Image.open(BytesIO(response.content))
# 预处理验证码图片
# ...
# 显示处理后的验证码图片
image.show()
posted on
浙公网安备 33010602011771号