文字点选是通过调用百度AI的文字识别接口,经过测试验证通过率不解释,能完成登录就行了
"""
@time: 2021/5/28 9:45
"""
from pprint import pprint
from selenium import webdriver
from selenium.webdriver import ActionChains
import time
import base64
from PIL import Image
from aip import AipOcr
from selenium.webdriver.chrome.options import Options
class UnLockScrapy(object):
def __init__(self, name, pwd):
super(UnLockScrapy, self).__init__()
self.name = name
self.pwd = pwd
self.WAPPID = '24*****98'
self.WAPPKEY = '6BWCE3WjFon*****qjkFcCljK'
self.WSECRETKEY = 'EKT8FiITv**9MMnjU*****1ujqOsVikS '
self.client = AipOcr(self.WAPPID, self.WAPPKEY, self.WSECRETKEY)
options = Options()
options.add_argument("--disable-blink-features=AutomationControlled")
options.add_experimental_option('useAutomationExtension', False)
options.add_experimental_option('excludeSwitches', ['enable-automation'])
options.add_argument('--disable-gpu')
options.add_argument('--no-sandbox')
options.add_experimental_option("detach", True)
self.driver = webdriver.Chrome(options=options)
login_url = "https://passport.ctrip.com/user/login?BackUrl=https%3A%2F%2Fhotels.ctrip.com%2Fhotel%2F6278770.html%23ctm_ref%3Dhod_hp_hot_dl_n_2_7"
self.driver.get(login_url)
self.driver.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument", {
"source": """
Object.defineProperty(navigator, 'webdriver', {
get: () => undefined
})
"""
})
print("浏览器初始化完成")
time.sleep(2)
input_name = self.driver.find_element_by_id("nloginname")
input_name.clear()
input_name.send_keys(self.name