最近有点时间,就随便找点东西弄弄,倒也碰到了一些问题,在此记录下
Python3.11.3 + selenium4.9.1 + opencv4.7 + PyAutoGUI0.9.54 + windows11
进入登录页面,登录方式有两种,这里直接定位点击账号登录即可
1 2 3 4 5 6 7 8 9 10 11 12 |
|
看到验证码的图片是base64格式的,可以通过src属性来获取,然后直接转成cv图片格式即可
1 2 3 4 5 6 7 8 9 |
|
?
?
这里可以用opencv来做,正确率还不错,而且还简单,直接把两张验证码图片经过灰度后,进行模板匹配即可,不过最后的结果还需要根据网页元素的尺寸进行调整
1 2 3 4 5 6 7 8 9 10 |
|
之前一直使用selenium的ActionChains来操作滑块按钮,但是一直通不过,应该是jd有针对selenium有检测,后面参考了网上可以使用PyAutoGUI来控制鼠标来滑动,那就需要先定位到滑块的坐标,但是通过selenium获取的坐标还需要调整一下PyAutoGUI才能正确的定位到
1 2 3 4 5 |
|
滑的时候发现上面opencv计算的移动距离还是有些偏差,还需要做些调整,而且滑动也得尽量拟人化,不然滑对了也通不过
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
|
到此基本上模拟登陆就完成了,避免失败,可以加个循环,滑块未通过时继续下一张,再做一些是否登录成功的验证就欧克啦。
?现在我也找了很多测试的朋友,做了一个分享技术的交流群,共享了很多我们收集的技术文档和视频教程。
如果你不想再体验自学时找不到资源,没人解答问题,坚持几天便放弃的感受
可以加入我们一起交流。而且还有很多在自动化,性能,安全,测试开发等等方面有一定建树的技术大牛
分享他们的经验,还会分享很多直播讲座和技术沙龙
可以免费学习!划重点!开源的!!!
qq群号:485187702【暗号:csdn11】
最后感谢每一个认真阅读我文章的人,看着粉丝一路的上涨和关注,礼尚往来总是要有的,虽然不是什么很值钱的东西,如果你用得到的话可以直接拿走!?希望能帮助到你!【100%无套路免费领取】