Python,selenium + PIL模块处理图片问题

前概: 写个小脚本,自动化登录,因需要验证码的填写
暂时使用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方法是不是有些其他因素没考虑到

https://blog.csdn.net/llf_cloud/article/details/84310644
感谢大佬的解读,大佬链接

在这里插入图片描述

于是乎将参数值进行1.25倍(PC缩放比例)放大即可截取正常图片

在这里插入图片描述
有了需要的图片后可进行下一步,图像识别,未完待续~

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值