
"""sorted(title_extracted_by_h,key = lambda x:similarity(x,title_extracted_by_title),reverse=True)

etree.strip_elements(elements,tag) #tag是要删除的标签名
for child in children(element):  #children(element)是一个函数，获取当前HTML元素的所有子元素
    child.tag.lower() #获取标签名称
    etree.strip_tags(child,'span') #删除标签对

element.getparent() #获取给定元素的父元素


"""
# from io import StringIO
#
# import pandas as pd
# data = '"1234","456\r7","897"'
# print(data)
# aa = pd.read_csv(StringIO(data),escapechar='\r')
# print(aa)

# import pandas as pd
#
# # 读取txt文件
# data = pd.read_csv('D:\\美国证券交易委员会\\2022q4\\sub.txt', delimiter='\t')  # 根据实际情况选择正确的分隔符
#
# # 将数据保存为csv文件
# data.to_csv('D:\\美国证券交易委员会\\2022q4\\sub.csv', index=False)  # index=False表示不保存行索引
"""验证码识别测试"""
# import ddddocr
#
# ocr = ddddocr.DdddOcr()
#
# with open("D:\\kkwork\\captchaNew (3).jfif", 'rb') as f:
#     image = f.read()
#
# res = ocr.classification(image)
# print(res)
"""测试中国执行信息公开网  模拟浏览器"""

import ddddocr
from PIL import Image
import re

import requests, time, random, json, pymysql, redis

import urllib3
from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from obs import ObsClient
from kafka import KafkaProducer

from base.BaseCore import BaseCore
baseCore = BaseCore()
log = baseCore.getLogger()
cnx_ = baseCore.cnx
cursor_ = baseCore.cursor

def use_ocr(img):
    ocr = ddddocr.DdddOcr()
    with open(img, 'rb') as f:
        image = f.read()
    res = ocr.classification(image)
    print(res)
    return res

if __name__=="__main__":
    requests.DEFAULT_RETRIES = 5
    time_start = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
    log.info(f'开始时间为：{time_start}')

    requests.adapters.DEFAULT_RETRIES = 3
    headers = {
        'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36',
    }

    opt = webdriver.ChromeOptions()
    opt.add_argument(
        'user-agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36')

    opt.add_argument("--ignore-certificate-errors")
    opt.add_argument("--ignore-ssl-errors")
    opt.add_experimental_option("excludeSwitches", ["enable-automation"])
    opt.add_experimental_option('excludeSwitches', ['enable-logging'])
    opt.add_experimental_option('useAutomationExtension', False)
    opt.binary_location = r'D:/Google/Chrome/Application/chrome.exe'
    chromedriver = r'D:/cmd100/chromedriver.exe'
    browser = webdriver.Chrome(chrome_options=opt, executable_path=chromedriver)
    url = "http://zxgk.court.gov.cn/shixin/"
    browser.get(url)
    # 可改动
    time.sleep(20)
    page_source = browser.page_source
    soup = BeautifulSoup(page_source, 'html.parser')
    img_url = soup.select('img[id="captchaImg"]')[0]['src']

    browser.find_element(By.ID, 'pName').send_keys('北京远翰国际教育咨询有限责任公司')


    browser.find_element(By.ID, 'yzm').send_keys(yzm)
    browser.find_element(By.ID, 'searchForm').click()
    wait = WebDriverWait(browser, 30)
    wait.until(EC.presence_of_element_located((By.TAG_NAME, "body")))

# screen_img_path = "D:/screen/xxx.png"
# out_img_path = "D:/out/xxx.png"
# ele = driver.find_element(By.ID, 'XXXX')
#
# code = use_ocr(out_img_path)
# 验证码输入框元素.send_keys(code)
