bilibili_待验证_移动1像素,休眠0.0001-0.0003,再循环,再移动1像素_pause 休眠

import random
from selenium.webdriver import Chrome
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.chrome.options import Options # 浏览器信息配置
import json
import requests
import time


# 给浏览器加配置信息

opt = Options()

opt.add_argument("--disable-blink-features=AutomationControlled")
web = Chrome(options=opt)


def base64_api(img, typeid=27, uname="q6035945", pwd="q6035945"): # 用户名,密码,图片,类型
data = {"username": uname, "password": pwd, "typeid": typeid, "image": img}
result = json.loads(requests.post("http://api.ttshitu.com/predict", json=data).text)
if result['success']:
return result["data"]["result"]
else:
# !!!!!!!注意:返回 人工不足等 错误情况 请加逻辑处理防止脚本卡死 继续重新 识别
return result["message"]


web.get('https://www.bilibili.com/')

web.implicitly_wait(10) # 第一件事,等待
result = VerifyCode().verify_quekou_dan("tu.png")
web.execute_script("""
document.getElementsByClassName('geetest_canvas_slice')[0].style.display='block';
""")
print(result)
btn = web.find_element(By.XPATH, '')
target = int(result)

# 下面才是重点
ac = ActionChains(web)
ac.move_to_element(btn).click_and_hold(btn) # 抓住它

x = 0
while x <= target:
ac.move_by_offset(1, 0).move_to_element(btn) # 移动1像素,休眠0.0001-0.0003,再循环,再移动1像素
ac.pause(random.uniform(0.0001, 0.0003)) # pause 休眠
x += 1

# t = target - x
# x = 0
# while x < 3:
# move_px = random.randint(-1, 3)
# ac.move_by_offset(move_px, 0)
# ac.pause(random.uniform(0.03, 0.06))
# x += move_px
#
# t -= x
# ac.move_by_offset(t, 0)

ac.move_by_offset(2, 0).move_to_element(btn) # 得瑟 往前挪一点
ac.move_by_offset(-1, 0).move_to_element(btn) # 得瑟 往后挪一点
ac.move_by_offset(-2, 0).move_to_element(btn) # 得瑟 往后再挪一点
ac.move_by_offset(1, 0).move_to_element(btn) # 得瑟 再往前挪一点

ac.pause(random.uniform(0.03, 0.06))
ac.move_to_element(btn)
x = 0
while x <= 6:
ac.move_by_offset(-1, 0).move_to_element(btn)
ac.pause(random.uniform(0.001, 0.003)) # pause 休眠
x += 1

ac.pause(0.358)
ac.move_to_element(btn)
ac.release().perform()





































posted @ 2023-08-11 22:55  严永富  阅读(9)  评论(0)    收藏  举报