前概: 写个小脚本,自动化登录,因需要验证码的填写
暂时使用OCR识别验证码进行破解,处理验证码填写逻辑,继而进行登录
工具: Python + Selenium + PIL + muggle_ocr
Error: SystemError: tile cannot extend outside image
Traceback (most recent call last):
File "C:\Users\Bayue\AppData\Local\Programs\Python\Python37\lib\site-packages\PIL\ImageFile.py", line 496, in _save
fh = fp.fileno()
AttributeError: '_idat' object has no attribute 'fileno'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:/projects/python/demo/screenn.py", line 30, in <module>
pic.save("pic2.png")
File "C:\Users\Bayue\AppData\Local\Programs\Python\Python37\lib\site-packages\PIL\Image.py", line 2134, in save
save_handler(self, fp, filename)
File "C:\Users\Bayue\AppData\Local\Programs\Python\Python37\lib\site-packages\PIL\PngImagePlugin.py", line 1291, in _save
ImageFile._save(im, _idat(fp, chunk), [("zip", (0, 0) + im.size, 0, rawmode)])
File "C:\Users\Bayue\AppData\Local\Programs\Python\Python37\lib\site-packages\PIL\ImageFile.py", line 504, in _save
e.setimage(im.im, b)
SystemError: tile cannot extend outside image
解决: 思路为看报错信息,看不懂进行谷歌翻译,然后翻译也看不懂,粘贴百度,发现是因为PIL模块crop函数进行处理图片时范围超出了限制
ex:
接上述所说,自己可以慢慢摸索到一个坐标距离
但是仅针对于这一副图片,写死的坐标,这样解决得一时问题,无法从根本找到原因,故换个思路,从源头思考,selenium location方法是不是有些其他因素没考虑到
感谢大佬的解读,大佬链接
于是乎将参数值进行1.25倍(PC缩放比例)放大即可截取正常图片
有了需要的图片后可进行下一步,图像识别,未完待续~