去掉自动化标识,绕过js,绕过ip
import time
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
option = Options()
option.add_experimental_option('excludeSwitches', ['enable-automation'])
option.add_argument('--disable-blink-features=AutomationControlled')
option.add_argument(r'--user-data-dir=C:\Users\PC\AppData\Local\Google\Chrome\User Data')
time.sleep(2)
driver = webdriver.Chrome(options = option)
图形验证码获取
import ddddocr
from selenium import webdriver
imgelement = driver.find_element('xpath','/html/body/div[1]/div/div[2]/div/div[2]/div/div/div[3]/div[2]/div/div/img')
imgelement.screenshot('captcha.jpg')
ocr = ddddocr.DdddOcr()
with open('captcha.jpg', 'rb') as f:
img_bytes = f.read()
res = ocr.classification(img_bytes)
print('识别出的验证码为:' + res)
driver.find_element_by_id(yanzhengmaid).send_keys(res)
获取用户名的 动态id,并通过id定位元素
nameId=driver.find_element_by_xpath("//input[starts-with(@id,169)]").get_attribute("id")
driver.find_element_by_id(nameId).send_keys('yonghuming')
passwordId=driver.find_element_by_xpath("//input[ends-with(@id,'ps-k')]").get_attribute("id")
driver.find_element_by_id(passwordId).send_keys('mima')
testId=driver.find_element_by_xpath("//input[contains(@id,'test')]").get_attribute("id")
driver.find_element_by_id(testId).click()