一、图片验证码的识别。
img_url=driver.find_element(By.ID,'login_idCode').get_attribute("src")
# 定义请求头
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36'}
response = requests.get(img_url, headers=headers)
img_data = response.content
cocr = ocr.DdddOcr(show_ad=False)
ret = cocr.classification(img_data)
二、页面弹窗窗口后的获取。
current_handle=driver.current_window_handle
handles = driver.window_handles
for handle in handles:
if handle !=current_handle:
driver.switch_to.window(handle)
##条件识别
break
三、Centos 平台浏览器设置
# 进入浏览器设置
options = webdriver.ChromeOptions()
# 设置中文
options.add_argument('lang=zh_CN.UTF-8')
options.add_experimental_option("excludeSwitches", ['enable-automation', 'enable-logging'])
# 更换头部
options.add_argument('user-agent="Mozilla/5.0 (iPod; U; CPU iPhone OS 2_1 like Mac OS X; ja-jp) AppleWebKit/525.18.1 (KHTML, like Gecko) Version/3.1.1 Mobile/5F137 Safari/525.20"')
##忽略浏览器错误
options.add_argument('-ignore-certificate-errors')
options.add_argument('-ignore -ssl-errors')
##更改下载目录
prefs = {"download.default_directory": './downloads'}
#add_experimental_option表示将这些首选项添加到他们的Selenium Webdriver对象中
options.add_experimental_option("prefs", prefs)
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--disable-gpu')
options.add_argument('--disable-dev-shm-usage')
#get直接返回,不再等待界面加载完成
desired_capabilities = DesiredCapabilities.CHROME
desired_capabilities["pageLoadStrategy"] = "none"
service = Service('/usr/lib64/chromedriver/chromedriver')
driver = webdriver.Chrome(service=service, options=options)
作者Q:245511691