当前位置:   article > 正文

【Python selenium过极验五子棋】自动化过五子棋人机验证,享受丝滑的落子,秒了

【Python selenium过极验五子棋】自动化过五子棋人机验证,享受丝滑的落子,秒了

文章日期:2024.07.25

使用工具:Python

文章类型:自动化过极验五子棋

文章全程已做去敏处理!!!  【需要做的可联系我】 

AES解密处理(直接解密即可)(crypto-js.js 标准算法):​​​​​​在线AES加解密工具

【点赞 收藏 关注 】仅供学习,仅供学习。

今天用Python 的 selenium模块,自动化过极验五子棋,先看视频

这个是手动验证的,需要输入指定数字才能开始验证,是一个while死循环,是为了方便展示

1、五子棋人机验证比上一次的哪个消消乐还要简单,哪个消消乐的图片的url全部都不一样,这个五子棋的图片的url都是一样的,又节约了时间和流量
2、这次的人机验证也没什么难度,看图说话

3、难度不大,也没什么好讲的,有些注释没写是因为屎山不需要注释,其次是因为我写代码时都是突然来的灵感,没来的及写,等回过头就忘了要写什么注释了,干脆就不写了,总之我都会,你们不会的可以自己研究一下,还不会就留言,等我给你慢慢讲

【附上代码】教程可能不是很清晰明了,有不懂可以留言或私信

  1. from selenium import webdriver
  2. from selenium.webdriver.common.by import By
  3. import time
  4. import re
  5. import hashlib
  6. def md5_encrypt(string):
  7. md5 = hashlib.md5()
  8. md5.update(string.encode('utf-8'))
  9. return md5.hexdigest()
  10. # 配置 Chrome 浏览器
  11. chrome_options = webdriver.ChromeOptions()
  12. chrome_options.binary_location = "chrome/chrome.exe" # 指定 Chrome 浏览器的路径
  13. chrome_options.add_argument("--disable-infobars") # 禁用浏览器中的"信息栏",避免干扰测试。
  14. # 启动浏览器
  15. driver = webdriver.Chrome(options=chrome_options)
  16. # 打开 Google
  17. driver.get("http://gt4.geetest.com/")
  18. print('点击开始验证')
  19. time.sleep(0.5)
  20. # 点击配置
  21. driver.find_element(By.XPATH, r'/html/body/div/div/div[4]/div[1]').click()
  22. time.sleep(0.5)
  23. # 点击五子棋验证
  24. driver.find_element(By.XPATH, r'/html/body/div/div/div[4]/div[2]/div[2]/div[1]/div[2]/div[3]/div[6]').click()
  25. time.sleep(0.5)
  26. # 点击验证按钮
  27. driver.find_element(By.XPATH, r'/html/body/div/div/div[2]/div[2]/form/div[3]/div[3]/div[1]/div[1]').click()
  28. print('等待加载')
  29. data = driver.page_source
  30. # 字典格式的数据
  31. list_chart1 = []
  32. # 数据转哈希
  33. list_chart2 = []
  34. # 上下
  35. for _y in range(5):
  36. # 左右
  37. for _x in range(5):
  38. if re.findall(f'geetest_item-{_y}-{_x} geetest_itemimg geetest_isEmpty', data):
  39. chart_url = ''
  40. else:
  41. chart_url = md5_encrypt(re.findall(f'geetest_item-{_y}-{_x}_.*?url\("(.*?)"\)', data)[0])
  42. list_chart1 += [{f'{_y+1}-{_x+1}': chart_url}]
  43. list_chart2 += [chart_url]
  44. print(f'五子棋已排列完成:{list_chart1}')
  45. # 去重
  46. quchong = []
  47. # 要查找的参数
  48. chuang = ''
  49. # 目标棋子 & 重点坐标
  50. target = ['','']
  51. print('开始检测五子棋并查找缺口!!!')
  52. if list_chart2[4::4][:-1].count('') == 1 and len(set(list_chart2[4::4][:-1])) == 2:
  53. quchong += ['1-5','2-4','3-3','4-2','5-1']
  54. chuang = list(filter(None, set(list_chart2[4::4][:-1])))[0]
  55. target[1] = f'{list_chart2[4::4][:-1].index("")+1}-{6-(list_chart2[4::4][:-1].index("")+1)}'
  56. if list_chart2[::6].count('') == 1 and len(set(list_chart2[::6])) == 2:
  57. quchong += ['1-1','2-2','3-3','4-4','5-5']
  58. chuang = list(filter(None, set(list_chart2[::6])))[0]
  59. target[1] = f'{list_chart2[::6].index("")+1}-{list_chart2[::6].index("")+1}'
  60. for number in range(5):
  61. number_1 = number * 5
  62. if list_chart2[number_1:number_1+5].count('') == 1 and len(set(list_chart2[number_1:number_1+5])) == 2:
  63. quchong += [f'{number_1 // 5 + 1}-{a+1}' for a in range(5)]
  64. chuang = list(filter(None, set(list_chart2[number_1:number_1+5])))[0]
  65. target[1] = list(list_chart1[number_1+list_chart2[number_1:number_1+5].index('')].keys())[0]
  66. if list_chart2[number::5].count('') == 1 and len(set(list_chart2[number::5])) == 2:
  67. quchong += [f'{a+1}-{number+1}' for a in range(5)]
  68. chuang = list(filter(None,set(list_chart2[number::5])))[0]
  69. target[1] = list(list_chart1[number+list_chart2[number::5].index('')*5].keys())[0]
  70. if quchong:
  71. for _ in list_chart1:
  72. if list(_.keys())[0] not in quchong and list(_.values())[0] == chuang:
  73. target[0] = list(_.keys())[0]
  74. break
  75. print(f'缺口方位:{target[0]} 目标棋子方位:{target[1]}')
  76. print('准备移动 - 略等2秒,怕页面没加载出来!!!')
  77. # 此处要加间隔时间,防止图片没有加载出来
  78. time.sleep(2)
  79. driver.find_element(By.XPATH,
  80. rf'/html/body/div/div/div[2]/div[2]/form/div[3]/div[3]/div[1]/div[4]/div[1]/div[2]/div/div[2]/div[{target[0].split("-")[0]}]/div[{int(target[0].split("-")[1])*2}]').click()
  81. time.sleep(0.1)
  82. driver.find_element(By.XPATH,
  83. rf'/html/body/div/div/div[2]/div[2]/form/div[3]/div[3]/div[1]/div[4]/div[1]/div[2]/div/div[2]/div[{target[1].split("-")[0]}]/div[{int(target[1].split("-")[1])*2}]').click()
  84. print('验证成功!!!')
  85. print('等待执行其他操作!!!\n\n')
  86. time.sleep(10000)
  87. # 关闭浏览器
  88. driver.quit()

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小舞很执着/article/detail/919217
推荐阅读
相关标签
  

闽ICP备14008679号