コード例 #1
0
ファイル: patent.py プロジェクト: DongDong-123/zgg_active
 def __init__(self):
     self.common = Common()
     self.timetemp = time.strftime("%Y-%m-%d-%H-%M-%S",
                                   time.localtime())  # 存储Excel表格文件名编号
     self.db = "case"
     self.dboperate = DbOperate()
     self.windows = None
     self.report_path = ReadConfig().save_report()
     self.catlog = 1
コード例 #2
0
ファイル: copyright.py プロジェクト: DongDong-123/zgg_active
 def __init__(self):
     self.driver = driver
     self.timetemp = time.strftime("%Y-%m-%d-%H-%M-%S",
                                   time.localtime())  # 存储Excel表格文件名编号
     # 每个案件的数量
     self.number = 1
     self.dboperate = DbOperate()
     self.db = "copyright"
     self.windows = None
     self.report_path = ReadConfig().save_report()
コード例 #3
0
 def __init__(self):
     self.common = Common()
     # 登录
     self.common.driver = self.common.driver
     # Excel写入
     self.row = 0
     self.workbook = xlwt.Workbook(encoding='utf-8')
     self.booksheet = self.workbook.add_sheet('Sheet1')
     self.timetemp = time.strftime("%Y-%m-%d-%H-%M-%S",
                                   time.localtime())  # 存储Excel表格文件名编号
     # 每个案件的数量
     self.number = 1
     self.report_path = ReadConfig().save_report()
     self.dboperate = DbOperate()
     self.db = "case"
     self.catlog = 2
コード例 #4
0
 def __init__(self):
     self.common = Common()
     # 登录
     self.driver = self.common.driver
     # Excel写入
     self.row = 0
     self.workbook = xlwt.Workbook(encoding='utf-8')
     self.booksheet = self.workbook.add_sheet('Sheet1')
     self.timetemp = time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime())  # 存储Excel表格文件名编号
     # 每个案件的数量
     self.number = 1
     self.report_path = ReadConfig().save_report()
     self.case_count = FunctionName.get_count
     self.excel_number(("案件名称", "案件号", "详情页价格", "下单页价格", "下单页总价格", "支付页总价格", "价格状态"))
     self.dboperate = DbOperate()
     self.windows = None
     self.db = "case"
コード例 #5
0
def send_clue():
    all_type = ReadConfig().get_clue_type()
    # 随机数量
    num = 5
    all_type = random_list(num, all_type)
    DbOperate().add("clue", all_type)
    qq = Operate()
    qq.send_clue()
    print("线索发送完毕")
コード例 #6
0
 def __init__(self):
     # 读取配置文件中的 账号密码
     self.USER = ReadConfig().get_user()
     self.PASSWORD = ReadConfig().get_password()
     # 登录
     self.driver = driver
     # self.driver = front_login(self.USER, self.PASSWORD)
     # Excel写入
     self.row = 0
     self.workbook = xlwt.Workbook(encoding='utf-8')
     self.booksheet = self.workbook.add_sheet('Sheet1')
     self.timetemp = time.strftime("%Y-%m-%d-%H-%M-%S",
                                   time.localtime())  # 存储Excel表格文件名编号
     # 每个案件的数量
     self.number = 1
     self.report_path = ReadConfig().save_report()
     self.phone = self.USER
     self.file_name = self.save_clue_log(("手机号", "线索内容", "发送状态", "其他"))
     self.db = "clue"
     self.dboperate = DbOperate()
     self.wait = 1
     self.wait_time = 3
     self.add_clue = 1
コード例 #7
0
ファイル: copyright.py プロジェクト: DongDong-123/zgg_active
class Execute(object, metaclass=FunctionName):
    def __init__(self):
        self.driver = driver
        self.timetemp = time.strftime("%Y-%m-%d-%H-%M-%S",
                                      time.localtime())  # 存储Excel表格文件名编号
        # 每个案件的数量
        self.number = 1
        self.dboperate = DbOperate()
        self.db = "copyright"
        self.windows = None
        self.report_path = ReadConfig().save_report()

    # 存入数据库
    def save_to_mysql(self, parm):
        code = 0
        if isinstance(parm, list):
            parm.append(code)
        else:
            parm = list(parm)
            parm.append(code)
        res_code = connect(parm)
        print("存储状态", res_code)

    def write_error_log(self, info):
        error_log_path = os.path.join(
            self.report_path, "error_log_{}.log".format(
                time.strftime("%Y-%m-%d", time.localtime())))
        with open(error_log_path, "a", encoding="utf-8") as f:
            f.write("{}: ".format(
                time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())) + info +
                    "\n")

    # 执行下单
    def execute_function(self, callback):
        try:
            eval("self.{}()".format(callback))
        except Exception as e:
            print("错误信息:", e)
            self.write_error_log(callback)
            time.sleep(0.5)
            self.write_error_log(str(e))

    #
    def closed_windows(self, num):
        self.windows = self.driver.window_handles
        for n in range(num + 1, len(self.windows)):
            self.driver.switch_to.window(self.windows[n])
            self.driver.close()
        self.windows = self.driver.window_handles
        self.driver.switch_to.window(self.windows[num])

    # 计算机软件著作权登记
    def copyright_computer_software_01(self):
        all_type = [u'计算机软件著作权登记']
        type_code = ["computer"]
        for index, copyright_type in enumerate(all_type):
            if self.dboperate.exists(type_code[index]):
                try:
                    locator = (By.XPATH,
                               "//div[@class='isnav-first']/div[1]/h2")
                    WebDriverWait(self.driver, 30, 0.5).until(
                        EC.element_to_be_clickable(locator))
                    aa = self.driver.find_element_by_xpath(
                        "(.//div[@class='fl isnaMar'])[3]")
                    ActionChains(self.driver).move_to_element(aa).perform()
                    self.driver.find_element_by_link_text(
                        copyright_type).click()
                    # 切换至新窗口
                    self.windows = self.driver.window_handles
                    self.driver.switch_to.window(self.windows[-1])
                    # 服务类型:
                    for num in range(1, 7):
                        if self.dboperate.is_member(type_code[index], num):
                            self.driver.find_element_by_xpath(
                                "//ul[@p='232']/li[{}]/a".format(num)).click()
                            case_name = self.driver.find_element_by_xpath(
                                "//ul[@p='232']/li[{}]/a".format(num)).text
                            case_name = "-".join(
                                [str(copyright_type), case_name])

                            # 数量加减
                            # self.common.number_add()
                            # self.common.number_minus()
                            time.sleep(0.5)
                            while not self.driver.find_element_by_id(
                                    "totalfee").is_displayed():
                                time.sleep(0.5)
                            # 获取详情页 价格
                            detail_price = self.driver.find_element_by_xpath(
                                "(.//div[@class='sames']//label[@id='totalfee'])"
                            ).text
                            print("{}详情页价格".format(case_name), detail_price)
                            self.dboperate.del_elem(type_code[index], num)
                            self.save_to_mysql([case_name, detail_price])
                    self.closed_windows(0)
                except Exception as e:
                    print(e)
                    self.driver.switch_to.window(self.windows[0])
        time.sleep(1)

    # 美术作品著作权登记-30日
    def copyright_art_works_01(self):
        all_type = [u'美术作品著作权登记']
        type_code = ["art"]
        for index, copyright_type in enumerate(all_type):
            if self.dboperate.exists(type_code[index]):
                try:
                    locator = (By.XPATH,
                               "//div[@class='isnav-first']/div[1]/h2")
                    WebDriverWait(self.driver, 30, 0.5).until(
                        EC.element_to_be_clickable(locator))
                    aa = self.driver.find_element_by_xpath(
                        "(.//div[@class='fl isnaMar'])[3]")
                    ActionChains(self.driver).move_to_element(aa).perform()
                    self.driver.find_element_by_link_text(
                        copyright_type).click()
                    # 切换至新窗口
                    self.windows = self.driver.window_handles
                    self.driver.switch_to.window(self.windows[-1])
                    for num in range(1, 7):
                        if self.dboperate.is_member(type_code[index], num):
                            self.driver.find_element_by_xpath(
                                "//ul[@p='107538']/li[{}]/a".format(
                                    num)).click()
                            case_name = self.driver.find_element_by_xpath(
                                "//ul[@p='107538']/li[{}]/a".format(num)).text
                            case_name = "-".join(
                                [str(copyright_type), case_name])

                            # 数量加减
                            # self.common.number_add()
                            # # self.common.number_minus()
                            time.sleep(0.5)
                            while not self.driver.find_element_by_id(
                                    "totalfee").is_displayed():
                                time.sleep(0.5)
                            # 获取详情页 价格
                            detail_price = self.driver.find_element_by_xpath(
                                "(.//div[@class='sames']//label[@id='totalfee'])"
                            ).text
                            print("{}详情页价格".format(case_name), detail_price)

                            self.dboperate.del_elem(type_code[index], num)
                            self.save_to_mysql([case_name, detail_price])
                    self.closed_windows(0)

                except Exception as e:
                    print(e)
                    self.driver.switch_to.window(self.windows[0])
        time.sleep(1)

    # 文字作品著作权登记
    def copyright_writings_01(self):
        # 选择文字作品著作权登记
        all_type = [
            u'汇编作品著作权登记', u'文字作品著作权登记', u'摄影作品著作权登记', u'电影作品著作权登记',
            u'音乐作品著作权登记', u'曲艺作品著作权登记'
        ]
        type_code = [
            "compile", "word", "photography", "film", "music", "drama"
        ]
        for index, copyright_type in enumerate(all_type):
            if self.dboperate.exists(type_code[index]):
                try:
                    locator = (By.XPATH,
                               "//div[@class='isnav-first']/div[1]/h2")
                    WebDriverWait(self.driver, 30, 0.5).until(
                        EC.element_to_be_clickable(locator))
                    aa = self.driver.find_element_by_xpath(
                        "(.//div[@class='fl isnaMar'])[3]")
                    ActionChains(self.driver).move_to_element(aa).perform()
                    self.driver.find_element_by_link_text(
                        copyright_type).click()
                    # 切换至新窗口
                    self.windows = self.driver.window_handles
                    self.driver.switch_to.window(self.windows[-1])
                    # 案件类型:
                    for num in range(1, 7):
                        if self.dboperate.is_member(type_code[index], num):
                            self.driver.find_element_by_xpath(
                                "//ul[@id='ulType']/li[{}]/a".format(
                                    num)).click()
                            case_name = self.driver.find_element_by_xpath(
                                "//ul[@id='ulType']/li[{}]/a".format(num)).text
                            case_name = "-".join(
                                [str(copyright_type), case_name])

                            # 数量加减
                            # self.common.number_add()
                            # # self.common.number_minus()
                            time.sleep(0.5)
                            while not self.driver.find_element_by_id(
                                    "totalfee").is_displayed():
                                time.sleep(0.5)
                            # 获取详情页 价格
                            detail_price = self.driver.find_element_by_xpath(
                                "(.//div[@class='sames']//label[@id='totalfee'])"
                            ).text
                            print("{}详情页价格".format(case_name), detail_price)
                            self.dboperate.del_elem(type_code[index], num)
                            self.save_to_mysql([case_name, detail_price])
                    self.closed_windows(0)

                except Exception as e:
                    print(e)
                    self.driver.switch_to.window(self.windows[0])
        self.closed_windows(0)
        time.sleep(1)
コード例 #8
0
class Execute(object, metaclass=FunctionName):
    def __init__(self):
        self.common = Common()
        # 登录
        self.common.driver = self.common.driver
        # Excel写入
        self.row = 0
        self.workbook = xlwt.Workbook(encoding='utf-8')
        self.booksheet = self.workbook.add_sheet('Sheet1')
        self.timetemp = time.strftime("%Y-%m-%d-%H-%M-%S",
                                      time.localtime())  # 存储Excel表格文件名编号
        # 每个案件的数量
        self.number = 1
        self.report_path = ReadConfig().save_report()
        self.dboperate = DbOperate()
        self.db = "case"
        self.catlog = 2

    # 执行下单
    def execute_function(self, callback):
        try:
            eval("self.{}()".format(callback))
        except Exception as e:
            print("错误信息:", e)
            self.write_error_log(callback)
            time.sleep(0.5)
            self.write_error_log(str(e))

    def write_error_log(self, info):
        error_log_path = os.path.join(
            self.report_path, "error_log_{}.log".format(
                time.strftime("%Y-%m-%d", time.localtime())))
        with open(error_log_path, "a", encoding="utf-8") as f:
            f.write("{}: ".format(
                time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())) + info +
                    "\n")

    # 立即申请
    def apply_now(self):
        self.common.driver.find_element_by_xpath(
            "//div[@class='ui-zlsq-gwc']/a[1]").click()

    # 处理价格字符
    def process_price(self, price):
        if "¥" in price:
            price = price.replace("¥", '')
        return price

    # 国内商标
    def trademark_adviser_register(self):
        all_type = [u'专属顾问注册', u'专属加急注册', u'专属双享注册', u'专属担保注册']
        for trademark_type in all_type:
            if self.dboperate.is_member(self.db, trademark_type):
                try:
                    locator = (By.XPATH, "(.//div[@class='fl isnaMar'])[2]")
                    WebDriverWait(self.common.driver, 30, 0.5).until(
                        EC.element_to_be_clickable(locator))
                    aa = self.common.driver.find_element_by_xpath(
                        "(.//div[@class='fl isnaMar'])[2]")
                    ActionChains(
                        self.common.driver).move_to_element(aa).perform()
                    self.common.driver.find_element_by_link_text(
                        trademark_type).click()
                    # 切换至新窗口
                    self.common.windows = self.common.driver.window_handles
                    self.common.driver.switch_to_window(
                        self.common.windows[-1])

                    self.apply_now()
                    # 切换至选择商标分类页面
                    self.common.windows = self.common.driver.window_handles
                    self.common.driver.switch_to_window(
                        self.common.windows[-1])
                    while not self.common.driver.find_element_by_id(
                            "costesNum").is_displayed():
                        time.sleep(0.5)
                    # 获取详情页 价格
                    case_name = trademark_type
                    detail_price = self.common.driver.find_element_by_xpath(
                        "(.//div[@class='info-checkedtop']/p/span)").text
                    # detail_price = self.common.driver.find_element_by_xpath("(.//div[@class='bottomin']/p[1]/span)").text
                    # print("商标页价格", total_price)
                    detail_price = self.common.process_price(detail_price)

                    print("{}详情页价格".format(case_name), detail_price)
                    self.common.save_to_mysql(
                        [case_name, detail_price, self.catlog])

                    # 删除已执行的类型
                    self.dboperate.del_elem(self.db, trademark_type)
                    time.sleep(1)
                    self.common.closed_windows(0)
                except Exception as e:
                    print('错误信息', e)
                    self.common.driver.switch_to_window(self.common.windows[0])

    # 国际商标
    def trademark_international(self):
        all_type = [
            u'美国商标注册', u'日本商标注册', u'韩国商标注册', u'台湾商标注册', u'香港商标注册', u'德国商标注册',
            u'欧盟商标注册', u'马德里国际商标', u'非洲知识产权组织'
        ]
        for international_type in all_type:
            if self.dboperate.is_member(self.db, international_type):
                # print(self.dboperate.is_member(international_type))
                try:
                    locator = (By.XPATH,
                               ".//div[@class='isnav-first']/div[1]/h2")
                    WebDriverWait(self.common.driver, 30, 0.5).until(
                        EC.element_to_be_clickable(locator))
                    aa = self.common.driver.find_element_by_xpath(
                        "(.//div[@class='fl isnaMar'])[2]")
                    ActionChains(
                        self.common.driver).move_to_element(aa).perform()
                    self.common.driver.find_element_by_link_text(
                        international_type).click()
                    # 切换至新窗口
                    self.common.windows = self.common.driver.window_handles
                    self.common.driver.switch_to_window(
                        self.common.windows[-1])
                    # 商标分类
                    self.common.driver.find_element_by_xpath(
                        "//a[@class='theme-fl']").click()
                    time.sleep(0.5)
                    self.common.driver.find_element_by_xpath(
                        "//ul[@class='theme-ul']/li[1]/p").click()
                    time.sleep(0.5)
                    self.common.driver.find_element_by_xpath(
                        "//div[@class='theme-btn']/a[3]").click()
                    time.sleep(0.5)
                    while not self.common.driver.find_element_by_id(
                            "totalfee").is_displayed():
                        time.sleep(0.5)
                    # 获取详情页 价格
                    case_name = str(international_type)
                    detail_price = self.common.driver.find_element_by_xpath(
                        "(.//div[@class='sames']//label[@id='totalfee'])").text
                    print("{}详情页价格".format(case_name), detail_price)
                    self.dboperate.del_elem(self.db, international_type)
                    time.sleep(1)
                    self.common.save_to_mysql(
                        [case_name, detail_price, self.catlog])
                    self.common.closed_windows(0)
                except Exception as e:
                    print(e)
                    self.common.driver.switch_to_window(self.common.windows[0])

    # 共用部分
    def trademark_famous_brand(self):
        all_type = [
            u'申请商标更正', u'出具商标注册证明申请', u'补发商标注册证申请', u'商标转让', u'商标注销', u'商标变更',
            u'商标诉讼', u'证明商标注册', u'集体商标注册', u'驰名商标认定'
        ]
        for trademark in all_type:
            if self.dboperate.is_member(self.db, trademark):
                try:
                    locator = (By.XPATH, "(.//div[@class='fl isnaMar'])[2]")
                    WebDriverWait(self.common.driver, 30, 0.5).until(
                        EC.element_to_be_clickable(locator))
                    aa = self.common.driver.find_element_by_xpath(
                        "(.//div[@class='fl isnaMar'])[2]")
                    ActionChains(
                        self.common.driver).move_to_element(aa).perform()
                    self.common.driver.find_element_by_link_text(
                        trademark).click()
                    # 切换至新窗口
                    self.common.windows = self.common.driver.window_handles
                    self.common.driver.switch_to_window(
                        self.common.windows[-1])
                    while not self.common.driver.find_element_by_id(
                            "totalfee").is_displayed():
                        time.sleep(0.5)
                    # 获取详情页 价格
                    case_name = str(trademark)
                    detail_price = self.common.driver.find_element_by_xpath(
                        "(.//div[@class='sames']//label[@id='totalfee'])").text
                    print("{}详情页价格".format(case_name), detail_price)
                    self.dboperate.del_elem(self.db, trademark)
                    self.common.save_to_mysql(
                        [case_name, detail_price, self.catlog])

                    time.sleep(1)
                    self.common.closed_windows(0)
                except Exception as e:
                    print('错误信息', e)
                    self.common.driver.switch_to_window(self.common.windows[0])

        time.sleep(1)

    # 商标驳回复审-(普通,双保)
    def trademark_ordinary_reject(self):
        this_type = u'商标驳回复审'
        if self.dboperate.is_member(self.db, this_type):
            locator = (By.XPATH, ".//div[@class='isnav-first']/div[1]/h2")
            WebDriverWait(self.common.driver, 30,
                          0.5).until(EC.element_to_be_clickable(locator))
            aa = self.common.driver.find_element_by_xpath(
                "(.//div[@class='fl isnaMar'])[2]")
            ActionChains(self.common.driver).move_to_element(aa).perform()
            self.common.driver.find_element_by_link_text(this_type).click()
            # 切换至新窗口
            self.common.windows = self.common.driver.window_handles
            self.common.driver.switch_to_window(self.common.windows[-1])
            # 服务类型
            for num in [2271, 22712]:
                try:
                    self.common.driver.find_element_by_xpath(
                        ".//ul[@id='ulType']/li[@pt='{}']/a".format(
                            num)).click()
                    case_name = self.common.driver.find_element_by_xpath(
                        ".//ul[@id='ulType']/li[@pt='{}']/a".format(num)).text
                    case_name = "-".join([this_type, case_name])

                    # 数量加减
                    # self.common.number_add()
                    # # self.common.number_minus()
                    time.sleep(0.5)
                    while not self.common.driver.find_element_by_id(
                            "totalfee").is_displayed():
                        time.sleep(0.5)
                    # 获取详情页 价格
                    detail_price = self.common.driver.find_element_by_xpath(
                        "(.//div[@class='sames']//label[@id='totalfee'])").text
                    print("{}详情页价格".format(case_name), detail_price)
                    self.common.save_to_mysql(
                        [case_name, detail_price, self.catlog])
                except Exception as e:
                    print(e)
                    self.common.driver.switch_to_window(self.common.windows[1])
            self.common.closed_windows(0)
            self.dboperate.del_elem(self.db, this_type)
            time.sleep(1)

    # 商标异议 (异议申请、异议答辩)
    def trademark_objection_apply(self):
        this_type = u'商标异议'
        if self.dboperate.is_member(self.db, this_type):
            locator = (By.XPATH, ".//div[@class='isnav-first']/div[1]/h2")
            WebDriverWait(self.common.driver, 30,
                          0.5).until(EC.element_to_be_clickable(locator))
            aa = self.common.driver.find_element_by_xpath(
                "(.//div[@class='fl isnaMar'])[2]")
            ActionChains(self.common.driver).move_to_element(aa).perform()
            self.common.driver.find_element_by_link_text(this_type).click()
            # 切换至新窗口
            self.common.windows = self.common.driver.window_handles
            self.common.driver.switch_to_window(self.common.windows[-1])
            # 业务方向:异议申请、异议答辩、不予注册复审
            for num in [22721, 22722, 22723]:
                try:
                    self.common.driver.find_element_by_xpath(
                        ".//li[@pt='{}']/a".format(num)).click()
                    case_name = self.common.driver.find_element_by_xpath(
                        ".//li[@pt='{}']/a".format(num)).text
                    # 数量加减
                    # self.common.number_add()
                    # # self.common.number_minus()
                    case_name = "-".join([this_type, case_name])
                    while not self.common.driver.find_element_by_id(
                            "totalfee").is_displayed():
                        time.sleep(0.5)
                    # 获取详情页 价格
                    detail_price = self.common.driver.find_element_by_xpath(
                        "(.//div[@class='sames']//label[@id='totalfee'])").text
                    print("{}详情页价格".format(case_name), detail_price)
                    self.common.save_to_mysql(
                        [case_name, detail_price, self.catlog])

                except Exception as e:
                    print(e)
                    self.common.driver.switch_to_window(self.common.windows[1])
            self.common.closed_windows(0)
            self.dboperate.del_elem(self.db, this_type)
            time.sleep(1)

    # 商标撤三答辩--(商标撤三申请、商标撤三答辩)
    def trademark_brand_revoke_answer(self):
        this_type = u'商标撤销'
        if self.dboperate.is_member(self.db, this_type):
            locator = (By.XPATH, ".//div[@class='isnav-first']/div[1]/h2")
            WebDriverWait(self.common.driver, 30,
                          0.5).until(EC.element_to_be_clickable(locator))
            aa = self.common.driver.find_element_by_xpath(
                "(.//div[@class='fl isnaMar'])[2]")
            ActionChains(self.common.driver).move_to_element(aa).perform()
            self.common.driver.find_element_by_link_text(this_type).click()
            # 切换至新窗口
            self.common.windows = self.common.driver.window_handles
            self.common.driver.switch_to_window(self.common.windows[-1])
            # 业务方向:商标撤三申请、商标撤三答辩
            for num in range(1, 3):
                try:
                    self.common.driver.find_element_by_xpath(
                        ".//ul[@p='2273']/li[{}]/a".format(num)).click()
                    case_name = self.common.driver.find_element_by_xpath(
                        ".//ul[@p='2273']/li[{}]/a".format(num)).text
                    # 数量加减
                    # self.common.number_add()
                    # # self.common.number_minus()
                    case_name = "-".join([this_type, case_name])

                    time.sleep(0.5)
                    while not self.common.driver.find_element_by_id(
                            "totalfee").is_displayed():
                        time.sleep(0.5)
                    # 获取详情页 价格
                    detail_price = self.common.driver.find_element_by_xpath(
                        "(.//div[@class='sames']//label[@id='totalfee'])").text
                    print("{}详情页价格".format(case_name), detail_price)

                    self.common.save_to_mysql(
                        [case_name, detail_price, self.catlog])

                except Exception as e:
                    print(e)
                    self.common.driver.switch_to_window(self.common.windows[1])
            self.common.closed_windows(0)
            self.dboperate.del_elem(self.db, this_type)
            time.sleep(1)

    # 商标无效宣告--(商标无效宣告、商标无效宣告答辩)
    def trademark_brand_invalid_declare(self):
        this_type = u'商标无效'
        if self.dboperate.is_member(self.db, this_type):
            locator = (By.XPATH, ".//div[@class='isnav-first']/div[1]/h2")
            WebDriverWait(self.common.driver, 30,
                          0.5).until(EC.element_to_be_clickable(locator))
            aa = self.common.driver.find_element_by_xpath(
                "(.//div[@class='fl isnaMar'])[2]")
            ActionChains(self.common.driver).move_to_element(aa).perform()
            self.common.driver.find_element_by_link_text(this_type).click()
            # 切换至新窗口
            self.common.windows = self.common.driver.window_handles
            self.common.driver.switch_to_window(self.common.windows[-1])
            # 业务方向:商标无效宣告、商标无效宣告答辩
            for num in range(1, 3):
                try:
                    self.common.driver.find_element_by_xpath(
                        ".//ul[@p='2279']/li[{}]/a".format(num)).click()
                    case_name = self.common.driver.find_element_by_xpath(
                        ".//ul[@p='2279']/li[{}]/a".format(num)).text
                    case_name = "-".join([this_type, case_name])
                    # 数量加减
                    # self.common.number_add()
                    # # self.common.number_minus()

                    time.sleep(0.5)
                    while not self.common.driver.find_element_by_id(
                            "totalfee").is_displayed():
                        time.sleep(0.5)
                    # 获取详情页 价格
                    detail_price = self.common.driver.find_element_by_xpath(
                        "(.//div[@class='sames']//label[@id='totalfee'])").text
                    print("{}详情页价格".format(case_name), detail_price)
                    self.common.save_to_mysql(
                        [case_name, detail_price, self.catlog])

                except Exception as e:
                    print(e)
                    self.common.driver.switch_to_window(self.common.windows[1])
            self.common.closed_windows(0)
            self.dboperate.del_elem(self.db, this_type)
            time.sleep(1)

    # 商标续展--(续展申请、宽展申请、补发续展证明)
    def trademark_brand_extension_01(self):
        this_type = u'商标续展'
        if self.dboperate.is_member(self.db, this_type):
            locator = (By.XPATH, ".//div[@class='isnav-first']/div[1]/h2")
            WebDriverWait(self.common.driver, 30,
                          0.5).until(EC.element_to_be_clickable(locator))
            aa = self.common.driver.find_element_by_xpath(
                "(.//div[@class='fl isnaMar'])[2]")
            ActionChains(self.common.driver).move_to_element(aa).perform()
            self.common.driver.find_element_by_link_text(this_type).click()
            # 切换至新窗口
            self.common.windows = self.common.driver.window_handles
            self.common.driver.switch_to_window(self.common.windows[-1])
            # 业务方向:续展申请、宽展申请、补发续展证明
            for num in range(1, 4):
                try:
                    self.common.driver.find_element_by_xpath(
                        ".//ul[@p='2274']/li[{}]/a".format(num)).click()
                    case_name = self.common.driver.find_element_by_xpath(
                        ".//ul[@p='2274']/li[{}]/a".format(num)).text
                    case_name = "-".join([this_type, case_name])

                    # 数量加减
                    # self.common.number_add()
                    # # self.common.number_minus()
                    time.sleep(0.5)
                    while not self.common.driver.find_element_by_id(
                            "totalfee").is_displayed():
                        time.sleep(0.5)
                    # 获取详情页 价格
                    detail_price = self.common.driver.find_element_by_xpath(
                        "(.//div[@class='sames']//label[@id='totalfee'])").text
                    print("{}详情页价格".format(case_name), detail_price)
                    self.common.save_to_mysql(
                        [case_name, detail_price, self.catlog])

                except Exception as e:
                    print(e)
                    self.common.driver.switch_to_window(self.common.windows[1])
            self.common.closed_windows(0)
            self.dboperate.del_elem(self.db, this_type)
            time.sleep(1)

    # 商标许可备案 --(许可备案、变更(被)许可人名称、许可提前终止)
    def trademark_brand_permit(self):
        this_type = u'商标许可备案'
        if self.dboperate.is_member(self.db, this_type):
            locator = (By.XPATH, ".//div[@class='isnav-first']/div[1]/h2")
            WebDriverWait(self.common.driver, 30,
                          0.5).until(EC.element_to_be_clickable(locator))
            aa = self.common.driver.find_element_by_xpath(
                "(.//div[@class='fl isnaMar'])[2]")
            ActionChains(self.common.driver).move_to_element(aa).perform()
            self.common.driver.find_element_by_link_text(this_type).click()
            # 切换至新窗口
            self.common.windows = self.common.driver.window_handles
            self.common.driver.switch_to_window(self.common.windows[-1])
            # 业务方向:许可备案、变更(被)许可人名称、许可提前终止
            for num in range(1, 4):
                try:
                    self.common.driver.find_element_by_xpath(
                        ".//ul[@p='2278']/li[{}]/a".format(num)).click()
                    case_name = self.common.driver.find_element_by_xpath(
                        ".//ul[@p='2278']/li[{}]/a".format(num)).text
                    case_name = "-".join([this_type, case_name])

                    # 数量加减
                    # self.common.number_add()
                    # # self.common.number_minus()
                    time.sleep(0.5)
                    while not self.common.driver.find_element_by_id(
                            "totalfee").is_displayed():
                        time.sleep(0.5)
                    # 获取详情页 价格
                    detail_price = self.common.driver.find_element_by_xpath(
                        "(.//div[@class='sames']//label[@id='totalfee'])").text
                    print("{}详情页价格".format(case_name), detail_price)
                    self.common.save_to_mysql(
                        [case_name, detail_price, self.catlog])

                except Exception as e:
                    print(e)
                    self.common.driver.switch_to_window(self.common.windows[1])
            self.common.closed_windows(0)
            self.dboperate.del_elem(self.db, this_type)
            time.sleep(1)
コード例 #9
0
ファイル: patent.py プロジェクト: DongDong-123/zgg_active
class Execute(object, metaclass=FunctionName):
    def __init__(self):
        self.common = Common()
        self.timetemp = time.strftime("%Y-%m-%d-%H-%M-%S",
                                      time.localtime())  # 存储Excel表格文件名编号
        self.db = "case"
        self.dboperate = DbOperate()
        self.windows = None
        self.report_path = ReadConfig().save_report()
        self.catlog = 1

    # 执行下单
    def execute_function(self, callback):
        try:
            eval("self.{}()".format(callback))
        except Exception as e:
            print("错误信息:", e)
            self.common.write_error_log(callback)
            time.sleep(0.5)
            self.common.write_error_log(str(e))

    # # 关闭窗口
    # def closed_windows(self, num):
    #     self.windows = self.common.driver.window_handles
    #     for n in range(num + 1, len(self.windows)):
    #         self.common.driver.switch_to.window(self.windows[n])
    #         self.common.driver.close()
    #     self.common.driver.switch_to.window(self.windows[num])

    # 1 发明专利,实用新型,同日申请
    def patent_invention_normal(self):
        all_type = [u'发明专利', u'实用新型', u'发明新型同日申请']
        type_code = ["patent", "utility", "oneday"]
        for index, patent_type in enumerate(all_type):
            if self.dboperate.exists(type_code[index]):
                try:
                    locator = (By.XPATH, "(.//div[@class='fl isnaMar'])[1]")
                    WebDriverWait(self.common.driver, 30, 0.5).until(
                        EC.element_to_be_clickable(locator))
                    aa = self.common.driver.find_element_by_xpath(
                        "(.//div[@class='fl isnaMar'])[1]")
                    ActionChains(
                        self.common.driver).move_to_element(aa).perform()
                    self.common.driver.find_element_by_link_text(
                        patent_type).click()

                    # 切换至新窗口
                    self.windows = self.common.driver.window_handles
                    self.common.driver.switch_to.window(self.windows[-1])
                    for num in range(1, 8):
                        if self.dboperate.is_member(type_code[index], num):
                            # 服务类型选择,
                            if num < 4:
                                self.common.driver.find_element_by_xpath(
                                    ".//ul[@id='ulType']/li[{}]/a".format(
                                        num)).click()
                                case_name1 = self.common.driver.find_element_by_xpath(
                                    ".//ul[@id='ulType']/li[{}]/a".format(
                                        num)).text
                                case_name2 = ''
                            elif num == 4:
                                self.common.driver.find_element_by_xpath(
                                    ".//ul[@id='ulType']/li[1]/a").click()
                                # 消除悬浮窗的影响
                                temp = self.common.driver.find_element_by_xpath(
                                    ".//ul[@id='ulType']/li[2]/a")
                                ActionChains(
                                    self.common.driver).move_to_element(
                                        temp).perform()
                                self.common.driver.find_element_by_xpath(
                                    ".//div[@class='ui-increment-zl']//li[1]/a"
                                ).click()
                                case_name1 = self.common.driver.find_element_by_xpath(
                                    ".//ul[@id='ulType']/li[1]/a").text
                                case_name2 = self.common.driver.find_element_by_xpath(
                                    ".//div[@class='ui-increment-zl']//li[1]/a"
                                ).text
                            elif num == 5:
                                self.common.driver.find_element_by_xpath(
                                    ".//ul[@id='ulType']/li[2]/a").click()
                                self.common.driver.find_element_by_xpath(
                                    ".//div[@class='ui-increment-zl']//li[1]/a"
                                ).click()
                                case_name1 = self.common.driver.find_element_by_xpath(
                                    ".//ul[@id='ulType']/li[2]/a").text
                                case_name2 = self.common.driver.find_element_by_xpath(
                                    ".//div[@class='ui-increment-zl']//li[1]/a"
                                ).text
                            elif num == 6:
                                self.common.driver.find_element_by_xpath(
                                    ".//ul[@id='ulType']/li[3]/a").click()
                                self.common.driver.find_element_by_xpath(
                                    ".//div[@class='ui-increment-zl']//li[1]/a"
                                ).click()
                                case_name1 = self.common.driver.find_element_by_xpath(
                                    ".//ul[@id='ulType']/li[3]/a").text
                                case_name2 = self.common.driver.find_element_by_xpath(
                                    ".//div[@class='ui-increment-zl']//li[1]/a"
                                ).text
                            else:
                                self.common.driver.find_element_by_xpath(
                                    ".//li[@id='liguarantee']/a").click()
                                case_name1 = case_name = self.common.driver.find_element_by_xpath(
                                    ".//ul[@id='ulType']/li[3]/a").text
                                case_name2 = self.common.driver.find_element_by_xpath(
                                    ".//div[@class='ui-increment-zl']//li[2]/a"
                                ).text
                            # 数量加1
                            # self.common.number_add()
                            # 数量减1
                            # # self.common.number_minus()
                            if case_name2:
                                case_name = '-'.join((case_name1, case_name2))
                            else:
                                case_name = case_name1
                            case_name = "-".join((patent_type, case_name))
                            # 判断价格是否加载成功
                            while not self.common.driver.find_element_by_id(
                                    "totalfee").is_displayed():
                                time.sleep(0.5)
                            # 获取详情页 价格
                            detail_price = self.common.driver.find_element_by_xpath(
                                "(.//div[@class='sames']//label[@id='totalfee'])"
                            ).text
                            print("{}价格".format(case_name), detail_price)

                            self.dboperate.del_elem(type_code[index], num)
                            self.common.save_to_mysql(
                                [case_name, detail_price, self.catlog])
                            time.sleep(1)
                except Exception as e:
                    print(e)
                    self.common.driver.switch_to.window(self.windows[0])
                self.common.closed_windows(0)
                time.sleep(1)

    # 2 外观设计
    def patent_design(self):
        all_type = [u'外观设计']
        type_code = ["design"]
        for index, patent_type in enumerate(all_type):
            if self.dboperate.exists(type_code[index]):
                try:
                    locator = (By.XPATH, "(.//div[@class='fl isnaMar'])[1]")
                    WebDriverWait(self.common.driver, 30, 0.5).until(
                        EC.element_to_be_clickable(locator))
                    aa = self.common.driver.find_element_by_xpath(
                        "(.//div[@class='fl isnaMar'])[1]")
                    ActionChains(
                        self.common.driver).move_to_element(aa).perform()
                    self.common.driver.find_element_by_link_text(
                        patent_type).click()
                    # 切换至新窗口
                    self.windows = self.common.driver.window_handles
                    self.common.driver.switch_to.window(self.windows[-1])
                    for num in range(1, 7):
                        if self.dboperate.is_member(type_code[index], num):
                            # 服务类型选择,
                            if num <= 3:
                                self.common.driver.find_element_by_xpath(
                                    ".//ul[@id='ulType']/li[{}]/a".format(
                                        num)).click()
                                case_name1 = self.common.driver.find_element_by_xpath(
                                    ".//ul[@id='ulType']/li[{}]/a".format(
                                        num)).text
                                case_name2 = ''

                            elif num == 4:
                                self.common.driver.find_element_by_xpath(
                                    ".//ul[@id='ulType']/li[1]/a").click()
                                self.common.driver.find_element_by_xpath(
                                    ".//li[@id='liguarantee']/a").click()
                                case_name1 = self.common.driver.find_element_by_xpath(
                                    ".//ul[@id='ulType']/li[1]/a").text
                                case_name2 = self.common.driver.find_element_by_xpath(
                                    ".//li[@id='liguarantee']/a").text

                            elif num == 5:
                                self.common.driver.find_element_by_xpath(
                                    ".//ul[@id='ulType']/li[2]/a").click()
                                self.common.driver.find_element_by_xpath(
                                    ".//li[@id='liguarantee']/a").click()
                                case_name1 = self.common.driver.find_element_by_xpath(
                                    ".//ul[@id='ulType']/li[2]/a").text
                                case_name2 = self.common.driver.find_element_by_xpath(
                                    ".//li[@id='liguarantee']/a").text
                            else:
                                self.common.driver.find_element_by_xpath(
                                    ".//ul[@id='ulType']/li[3]/a").click()
                                self.common.driver.find_element_by_xpath(
                                    ".//li[@id='liguarantee']/a").click()
                                case_name1 = self.common.driver.find_element_by_xpath(
                                    ".//ul[@id='ulType']/li[3]/a").text
                                case_name2 = self.common.driver.find_element_by_xpath(
                                    ".//li[@id='liguarantee']/a").text
                            # 数量加1
                            # self.common.number_add()
                            # 数量减1
                            # # self.common.number_minus()
                            if case_name2:
                                case_name = '-'.join((case_name1, case_name2))
                            else:
                                case_name = case_name1

                            case_name = "-".join((patent_type, case_name))

                            # 判断价格是否加载成功
                            while not self.common.driver.find_element_by_id(
                                    "totalfee").is_displayed():
                                time.sleep(0.5)
                            # 获取详情页 价格
                            detail_price = self.common.driver.find_element_by_xpath(
                                "(.//div[@class='sames']//label[@id='totalfee'])"
                            ).text
                            print("{}价格".format(case_name), detail_price)

                            self.dboperate.del_elem(type_code[index], num)
                            self.common.save_to_mysql(
                                [case_name, detail_price, self.catlog])
                            time.sleep(1)
                except Exception as e:
                    print(e)
                    self.common.driver.switch_to.window(self.windows[0])
                self.common.closed_windows(0)
                time.sleep(1)

    # 3 专利申请复审,审查意见答复 -(发明专利,实用新型,外观设计)
    def patent_review_invention(self):
        all_type = [u'专利申请复审', u'审查意见答复']
        type_code = ["patent_recheck", "patent_answer"]
        ul_index = [13, 16]
        for index, patent_type in enumerate(all_type):
            if self.dboperate.exists(type_code[index]):
                try:
                    locator = (By.XPATH, "(.//div[@class='fl isnaMar'])[1]")
                    WebDriverWait(self.common.driver, 30, 0.5).until(
                        EC.element_to_be_clickable(locator))
                    aa = self.common.driver.find_element_by_xpath(
                        "(.//div[@class='fl isnaMar'])[1]")
                    ActionChains(
                        self.common.driver).move_to_element(aa).perform()
                    self.common.driver.find_element_by_link_text(
                        patent_type).click()
                    # 切换至新窗口
                    self.windows = self.common.driver.window_handles
                    self.common.driver.switch_to.window(self.windows[-1])
                    # 业务类型选择
                    for num in range(1, 4):
                        if self.dboperate.is_member(type_code[index], num):
                            self.common.driver.find_element_by_xpath(
                                ".//ul[@p='{}']/li[{}]/a".format(
                                    ul_index[index], num)).click()

                            case_name = self.common.driver.find_element_by_xpath(
                                ".//ul[@p='{}']/li[{}]/a".format(
                                    ul_index[index], num)).text
                            case_name = "-".join((patent_type, case_name))

                            # 数量加1
                            # self.common.number_add()
                            # 数量减1
                            # # self.common.number_minus()

                            while not self.common.driver.find_element_by_id(
                                    "totalfee").is_displayed():
                                time.sleep(0.5)
                            # 获取详情页 价格
                            detail_price = self.common.driver.find_element_by_xpath(
                                "(.//div[@class='sames']//label[@id='totalfee'])"
                            ).text
                            print("{}价格".format(case_name), detail_price)

                            self.dboperate.del_elem(type_code[index], num)
                            self.common.save_to_mysql(
                                [case_name, detail_price, self.catlog])
                            time.sleep(1)
                except Exception as e:
                    print(e)
                    self.common.driver.switch_to.window(self.windows[0])
                self.common.closed_windows(0)
        time.sleep(1)

    # 4 查新检索-国内评估,全球评估,第三方公众意见-无需检索,需要检索
    def patent_clue_domestic_1(self):
        all_type = [u'查新检索', u'第三方公众意见']
        type_code = ["patent_clue", "patent_public"]
        for index, patent_type in enumerate(all_type):
            if self.dboperate.exists(type_code[index]):
                try:
                    locator = (By.XPATH, "(.//div[@class='fl isnaMar'])[1]")
                    WebDriverWait(self.common.driver, 30, 0.5).until(
                        EC.element_to_be_clickable(locator))
                    aa = self.common.driver.find_element_by_xpath(
                        "(.//div[@class='fl isnaMar'])[1]")
                    ActionChains(
                        self.common.driver).move_to_element(aa).perform()
                    self.common.driver.find_element_by_link_text(
                        patent_type).click()
                    # 切换至新窗口
                    self.windows = self.common.driver.window_handles
                    self.common.driver.switch_to.window(self.windows[-1])
                    # 业务类型选择
                    for num in range(1, 3):
                        if self.dboperate.is_member(type_code[index], num):
                            self.common.driver.find_element_by_xpath(
                                ".//ul[@id='ulType']/li[{}]/a".format(
                                    num)).click()
                            case_name = self.common.driver.find_element_by_xpath(
                                ".//ul[@id='ulType']/li[{}]/a".format(
                                    num)).text
                            case_name = "-".join((patent_type, case_name))

                            # 数量加1
                            # self.common.number_add()
                            # 数量减1
                            # # self.common.number_minus()
                            while not self.common.driver.find_element_by_id(
                                    "totalfee").is_displayed():
                                time.sleep(0.5)
                            # 获取详情页 价格
                            detail_price = self.common.driver.find_element_by_xpath(
                                "(.//div[@class='sames']//label[@id='totalfee'])"
                            ).text
                            print("{}价格".format(case_name), detail_price)

                            self.dboperate.del_elem(type_code[index], num)
                            self.common.save_to_mysql(
                                [case_name, detail_price, self.catlog])
                            time.sleep(1)
                except Exception as e:
                    print(e)
                    self.common.driver.switch_to.window(self.windows[0])
                self.common.closed_windows(0)
        time.sleep(1)

    # 5 专利授权前景分析,专利稳定性分析 -(发明专利,实用新型,外观设计)
    def patent_warrant_invention_1(self):
        all_type = [u'授权前景分析', u'专利稳定性分析']
        type_code = ["patent_warrant", "patent_stable"]
        for index, patent_type in enumerate(all_type):
            if self.dboperate.exists(type_code[index]):
                try:
                    locator = (By.XPATH, "(.//div[@class='fl isnaMar'])[1]")
                    WebDriverWait(self.common.driver, 30, 0.5).until(
                        EC.element_to_be_clickable(locator))
                    aa = self.common.driver.find_element_by_xpath(
                        "(.//div[@class='fl isnaMar'])[1]")
                    ActionChains(
                        self.common.driver).move_to_element(aa).perform()
                    self.common.driver.find_element_by_link_text(
                        patent_type).click()
                    # 切换至新窗口
                    self.windows = self.common.driver.window_handles
                    self.common.driver.switch_to.window(self.windows[-1])
                    # 业务类型选择
                    for num in range(1, 4):
                        if self.dboperate.is_member(type_code[index], num):
                            self.common.driver.find_element_by_xpath(
                                ".//ul[@id='ulType']/li[{}]/a".format(
                                    num)).click()
                            case_name = self.common.driver.find_element_by_xpath(
                                ".//ul[@id='ulType']/li[{}]/a".format(
                                    num)).text
                            case_name = "-".join((patent_type, case_name))

                            # 数量加1
                            # self.common.number_add()
                            # 数量减1
                            # # self.common.number_minus()
                            while not self.common.driver.find_element_by_id(
                                    "totalfee").is_displayed():
                                time.sleep(0.5)
                            # 获取详情页 价格
                            detail_price = self.common.driver.find_element_by_xpath(
                                "(.//div[@class='sames']//label[@id='totalfee'])"
                            ).text
                            print("{}价格".format(case_name), detail_price)

                            self.dboperate.del_elem(type_code[index], num)
                            self.common.save_to_mysql(
                                [case_name, detail_price, self.catlog])
                            time.sleep(1)
                except Exception as e:
                    print(e)
                    self.common.driver.switch_to.window(self.windows[0])
                self.common.closed_windows(0)
        time.sleep(1)

    # 6 利权评价报告-实用新型,外观设计
    def patent_evaluate_utility(self):
        all_type = [u'专利权评价报告']
        type_code = ["patent_evaluate"]
        ul_index = [19]
        for index, patent_type in enumerate(all_type):
            if self.dboperate.exists(type_code[index]):
                try:
                    locator = (By.XPATH, "(.//div[@class='fl isnaMar'])[1]")
                    WebDriverWait(self.common.driver, 30, 0.5).until(
                        EC.element_to_be_clickable(locator))
                    aa = self.common.driver.find_element_by_xpath(
                        "(.//div[@class='fl isnaMar'])[1]")
                    ActionChains(
                        self.common.driver).move_to_element(aa).perform()
                    self.common.driver.find_element_by_link_text(
                        patent_type).click()
                    # 切换至新窗口
                    self.windows = self.common.driver.window_handles
                    self.common.driver.switch_to.window(self.windows[-1])
                    # 业务类型选择
                    for num in range(1, 3):
                        if self.dboperate.is_member(type_code[index], num):
                            self.common.driver.find_element_by_xpath(
                                ".//ul[@p='{}']/li[{}]/a".format(
                                    ul_index[index], num)).click()
                            case_name = self.common.driver.find_element_by_xpath(
                                ".//ul[@p='{}']/li[{}]/a".format(
                                    ul_index[index], num)).text
                            case_name = "-".join((patent_type, case_name))
                            # 数量加1
                            # self.common.number_add()
                            # 数量减1
                            # # self.common.number_minus()
                            while not self.common.driver.find_element_by_id(
                                    "totalfee").is_displayed():
                                time.sleep(0.5)
                            # 获取详情页 价格
                            detail_price = self.common.driver.find_element_by_xpath(
                                "(.//div[@class='sames']//label[@id='totalfee'])"
                            ).text
                            print("{}价格".format(case_name), detail_price)

                            self.dboperate.del_elem(type_code[index], num)
                            self.common.save_to_mysql(
                                [case_name, detail_price, self.catlog])
                            time.sleep(1)
                except Exception as e:
                    print(e)
                    self.common.driver.switch_to.window(self.windows[0])
                self.common.closed_windows(0)
        time.sleep(1)

    # 7著录项目变更
    def patent_description(self):
        all_type = [u'著录项目变更']
        type_code = ["description"]
        for index, patent_type in enumerate(all_type):
            if self.dboperate.exists(type_code[index]):
                try:
                    locator = (By.XPATH, "(.//div[@class='fl isnaMar'])[1]")
                    WebDriverWait(self.common.driver, 30, 0.5).until(
                        EC.element_to_be_clickable(locator))
                    aa = self.common.driver.find_element_by_xpath(
                        "(.//div[@class='fl isnaMar'])[1]")
                    ActionChains(
                        self.common.driver).move_to_element(aa).perform()
                    self.common.driver.find_element_by_link_text(
                        patent_type).click()
                    # 切换至新窗口
                    self.windows = self.common.driver.window_handles
                    self.common.driver.switch_to.window(self.windows[-1])
                    all_direction = [[1], [2], [3], [1, 2], [1, 3], [2, 3],
                                     [1, 2, 3]]

                    # =========随机选择一种类型===========
                    random_type = random.choice(all_direction)
                    random_index = all_direction.index(random_type)
                    all_direction = [random_type]
                    # ===================================

                    for index_2, num in enumerate(all_direction):
                        case_type = [str(patent_type)]
                        for temp in num:
                            # 业务类型选择
                            if temp == 1:
                                case_name1 = self.common.driver.find_element_by_xpath(
                                    ".//ul[@id='ul1']/li[1]/a").text
                                case_type.append(case_name1)
                            else:
                                self.common.driver.find_element_by_xpath(
                                    ".//ul[@id='ul1']/li[{}]/a".format(
                                        temp)).click()
                                case_name1 = self.common.driver.find_element_by_xpath(
                                    ".//ul[@id='ul1']/li[{}]/a".format(
                                        temp)).text
                                case_type.append(case_name1)

                        case_name = "-".join(case_type)

                        # 数量加1
                        # self.common.number_add()
                        # 数量减1
                        # # self.common.number_minus()
                        # 判断价格是否加载成功
                        while not self.common.driver.find_element_by_id(
                                "totalfee").is_displayed():
                            time.sleep(0.5)
                        # 获取详情页 价格
                        detail_price = self.common.driver.find_element_by_xpath(
                            "(.//div[@class='sames']//label[@id='totalfee'])"
                        ).text
                        print("{}价格".format(case_name), detail_price)

                        # 使用随机选择类型时,index_2改为random_index
                        self.dboperate.del_elem(type_code[index], random_index)
                        self.common.save_to_mysql(
                            [case_name, detail_price, self.catlog])
                        time.sleep(1)
                except Exception as e:
                    print(e)
                    self.common.driver.switch_to.window(self.windows[0])
                self.common.closed_windows(0)
                time.sleep(1)

    # 8 代缴专利年费
    def patent_replace(self):
        all_type = [u'代缴专利年费']
        for patent_type in all_type:
            if self.dboperate.is_member(self.db, patent_type):
                try:
                    locator = (By.XPATH, "(.//div[@class='fl isnaMar'])[1]")
                    WebDriverWait(self.common.driver, 30, 0.5).until(
                        EC.element_to_be_clickable(locator))
                    aa = self.common.driver.find_element_by_xpath(
                        "(.//div[@class='fl isnaMar'])[1]")
                    ActionChains(
                        self.common.driver).move_to_element(aa).perform()
                    self.common.driver.find_element_by_link_text(
                        patent_type).click()
                    # 切换至新窗口
                    self.windows = self.common.driver.window_handles
                    self.common.driver.switch_to.window(self.windows[-1])
                    while not self.common.driver.find_element_by_id(
                            "totalfee").is_displayed():
                        time.sleep(0.5)
                    # 获取详情页 价格
                    detail_price = self.common.driver.find_element_by_xpath(
                        "(.//div[@class='sames']//label[@id='totalfee'])").text
                    case_name = str(patent_type)
                    print("{}价格".format(case_name), detail_price)

                    self.dboperate.del_elem(self.db, patent_type)
                    self.common.save_to_mysql(
                        [case_name, detail_price, self.catlog])
                except Exception as e:
                    print('错误信息', e)
                    self.common.driver.switch_to.window(self.windows[0])
                self.common.closed_windows(0)

    # 9 PCT 国际申请-- 特殊处理
    def patent_PCT(self):
        all_type = [u'PCT国际申请']
        for patent_type in all_type:
            if self.dboperate.is_member(self.db, patent_type):
                try:
                    locator = (By.XPATH, "(.//div[@class='fl isnaMar'])[1]")
                    WebDriverWait(self.common.driver, 30, 0.5).until(
                        EC.element_to_be_clickable(locator))
                    aa = self.common.driver.find_element_by_xpath(
                        "(.//div[@class='fl isnaMar'])[1]")
                    ActionChains(
                        self.common.driver).move_to_element(aa).perform()
                    self.common.driver.find_element_by_link_text(
                        patent_type).click()
                    # 切换至新窗口
                    self.windows = self.common.driver.window_handles
                    self.common.driver.switch_to.window(self.windows[-1])
                    # 判断价格是否加载成功
                    while not self.common.driver.find_element_by_id(
                            "totalfee").is_displayed():
                        time.sleep(0.5)
                    # 获取详情页 价格
                    case_name = str(patent_type)
                    detail_price = self.common.driver.find_element_by_xpath(
                        "(.//div[@class='sames']//label[@id='totalfee'])").text
                    print("{}价格".format(case_name), detail_price)

                    self.dboperate.del_elem(self.db, patent_type)
                    self.common.save_to_mysql(
                        [case_name, detail_price, self.catlog])
                except Exception as e:
                    print('错误信息', e)
                    self.common.driver.switch_to.window(self.windows[0])
                self.common.closed_windows(0)

    # 10 共用部分
    def patent_common(self):
        all_type = [u'电商侵权处理', u'专利权恢复', u'专利实施许可备案', u'专利质押备案', u'集成电路布图设计']
        for patent_type in all_type:
            if self.dboperate.is_member(self.db, patent_type):
                try:
                    locator = (By.XPATH, "(.//div[@class='fl isnaMar'])[1]")
                    WebDriverWait(self.common.driver, 30, 0.5).until(
                        EC.element_to_be_clickable(locator))
                    aa = self.common.driver.find_element_by_xpath(
                        "(.//div[@class='fl isnaMar'])[1]")
                    ActionChains(
                        self.common.driver).move_to_element(aa).perform()
                    self.common.driver.find_element_by_link_text(
                        patent_type).click()
                    # 切换至新窗口
                    self.windows = self.common.driver.window_handles
                    self.common.driver.switch_to.window(self.windows[-1])
                    # 判断价格是否加载成功
                    while not self.common.driver.find_element_by_id(
                            "totalfee").is_displayed():
                        time.sleep(0.5)
                    # 获取详情页 价格
                    case_name = patent_type
                    detail_price = self.common.driver.find_element_by_xpath(
                        "(.//div[@class='sames']//label[@id='totalfee'])").text
                    print("{}价格".format(case_name), detail_price)

                    self.dboperate.del_elem(self.db, patent_type)
                    self.common.save_to_mysql(
                        [case_name, detail_price, self.catlog])

                except Exception as e:
                    print('错误信息', e)
                    self.common.driver.switch_to.window(self.windows[0])
                self.common.closed_windows(0)
コード例 #10
0
ファイル: patent.py プロジェクト: DongDong-123/zgg_test
 def __init__(self):
     self.common = Common()
     self.timetemp = time.strftime("%Y-%m-%d-%H-%M-%S",
                                   time.localtime())  # 存储Excel表格文件名编号
     self.db = "case"
     self.dboperate = DbOperate()
コード例 #11
0
class Execute(object, metaclass=FunctionName):
    def __init__(self):
        # 读取配置文件中的 账号密码
        self.USER = ReadConfig().get_user()
        self.PASSWORD = ReadConfig().get_password()
        # 登录
        self.driver = driver
        # self.driver = front_login(self.USER, self.PASSWORD)
        # Excel写入
        self.row = 0
        self.workbook = xlwt.Workbook(encoding='utf-8')
        self.booksheet = self.workbook.add_sheet('Sheet1')
        self.timetemp = time.strftime("%Y-%m-%d-%H-%M-%S",
                                      time.localtime())  # 存储Excel表格文件名编号
        # 每个案件的数量
        self.number = 1
        self.report_path = ReadConfig().save_report()
        self.phone = self.USER
        self.file_name = self.save_clue_log(("手机号", "线索内容", "发送状态", "其他"))
        self.db = "clue"
        self.dboperate = DbOperate()
        self.wait = 1
        self.wait_time = 3
        self.add_clue = 1

    def execute_function(self, callback):
        try:
            eval("self.{}()".format(callback))
            time.sleep(0.5)

        except Exception as e:
            print("错误信息:", e)
            self.write_error_log(callback)
            time.sleep(0.5)
            self.write_error_log(str(e))

    def make_phone(self):
        begin = 16619923387
        end = 16619933387
        return random.choice([num for num in range(begin, end)])

    def write_error_log(self, info):
        error_log_path = os.path.join(
            self.report_path, "error_log_{}.log".format(
                time.strftime("%Y-%m-%d", time.localtime())))
        with open(error_log_path, "a", encoding="utf-8") as f:
            f.write("{}: ".format(
                time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())) + info +
                    "\n")

    def save_clue_log(self, args):
        # 获取案件名称、案件号
        if args:
            n = 0
            for elem in args:
                self.booksheet.write(self.row, n, elem)
                self.booksheet.col(n).width = 300 * 28
                n += 1

        path = os.path.join(self.report_path,
                            "clue_{}.xls".format(self.timetemp))
        self.workbook.save(path)

    # 关闭窗口
    def closed_windows(self):
        self.driver.close()
        windows = self.driver.window_handles
        self.driver.switch_to.window(windows[-1])
        self.driver.close()
        self.driver.switch_to.window(windows[0])

    def check_rasult(self):
        result = self.driver.find_element_by_xpath(
            "(.//div[@class='them-edit-dialog']/div[@class='comm']/p)").text
        print("result", result, type(result))
        if "您的查询资料已提交" in result:
            response = "True"
        else:
            response = "False"
        return response

    # 专利线索12个
    def patent_clue_1_1(self):
        all_clue_type = [
            u'专利布局规划', u'研发立项支持', u'竞争对手监测', u'高价值专利培育', u'专利价值评估', u'专利尽职调查',
            u'专利价值评估', u'专利侵权诉讼', u'优先审查', u'海外专利流程管理', u'知识产权海关备案', u'植物新品种'
        ]
        for clue_type in all_clue_type:
            if self.dboperate.is_member(self.db, clue_type):
                try:
                    locator = (By.XPATH, "(.//div[@class='fl isnaMar'])[2]")
                    WebDriverWait(self.driver, 30, 0.5).until(
                        EC.element_to_be_clickable(locator))
                    aa = self.driver.find_element_by_xpath(
                        "(.//div[@class='fl isnaMar'])[1]")
                    ActionChains(self.driver).move_to_element(aa).perform()
                    self.driver.find_element_by_link_text(clue_type).click()
                    # 切换至新窗口
                    windows = self.driver.window_handles
                    self.driver.switch_to.window(windows[-1])

                    # 输入联系方式/联系人
                    case_name = self.driver.find_element_by_xpath(
                        "(.//div[@class='ui-apply-tit']/h3)").text
                    if self.add_clue:
                        self.phone = self.make_phone()
                        self.driver.find_element_by_id(
                            "consult_phone").send_keys(self.phone)
                    self.driver.find_element_by_id(
                        "consult_contact").send_keys(case_name)

                    # 提交需求
                    self.driver.find_element_by_xpath(
                        "(.//div[@class='ui-zlsq-gwc']/a)[1]").click()
                    time.sleep(0.5)

                    res = self.check_rasult()

                    self.driver.find_element_by_link_text(u'确定').click()
                    self.driver.close()
                    self.dboperate.del_elem(self.db, clue_type)

                    self.driver.switch_to.window(windows[0])
                    back_parm = (self.phone, case_name, res)
                    self.row = self.row + 1
                    self.save_clue_log(back_parm)
                    if self.wait:
                        print("休息{}s...".format(self.wait_time))
                        time.sleep(self.wait_time)
                except Exception as e:
                    print("发送错误:", e)
                    windows = self.driver.window_handles
                    self.driver.switch_to.window(windows[0])

    # 专利线索-国内国外
    def patent_clue_1_2(self):
        all_clue_type = [u'新产品风险预警(FTO)', u'侵权风险分析', u'行业专利导航']
        for clue_type in all_clue_type:
            if self.dboperate.is_member(self.db, clue_type):
                try:
                    locator = (By.XPATH, "(.//div[@class='fl isnaMar'])[2]")
                    WebDriverWait(self.driver, 30, 0.5).until(
                        EC.element_to_be_clickable(locator))
                    aa = self.driver.find_element_by_xpath(
                        "(.//div[@class='fl isnaMar'])[1]")
                    ActionChains(self.driver).move_to_element(aa).perform()
                    self.driver.find_element_by_link_text(clue_type).click()
                    # 切换至新窗口
                    windows = self.driver.window_handles
                    self.driver.switch_to.window(windows[-1])

                    # 随机选择一个类型
                    num = random.randint(1, 2)
                    print(num)
                    self.driver.find_element_by_xpath(
                        "(.//ul[@id='zlUlType']/li[{}]/a)".format(
                            num)).click()
                    time.sleep(0.5)
                    case_type = self.driver.find_element_by_xpath(
                        "(.//ul[@id='zlUlType']/li[{}]/a)".format(num)).text
                    time.sleep(0.5)

                    # 输入联系方式/联系人
                    case_name = self.driver.find_element_by_xpath(
                        "(.//div[@class='ui-apply-tit']//h3)").text
                    if self.add_clue:
                        self.phone = self.make_phone()
                        self.driver.find_element_by_id(
                            "consult_phone").send_keys(self.phone)
                    self.driver.find_element_by_id(
                        "consult_contact").send_keys(case_name + "-" +
                                                     case_type)

                    # 提交需求
                    self.driver.find_element_by_xpath(
                        "(.//div[@class='ui-zlsq-gwc']/a)[1]").click()
                    time.sleep(0.5)
                    # 判断是否成功推送
                    res = self.check_rasult()
                    self.driver.find_element_by_link_text(u'确定').click()
                    self.driver.close()
                    self.driver.switch_to.window(windows[0])
                    self.dboperate.del_elem(self.db, clue_type)
                    back_parm = (self.phone, case_name, res)
                    self.row = self.row + 1
                    self.save_clue_log(back_parm)
                    if self.wait:
                        print("休息{}s...".format(self.wait_time))
                        time.sleep(self.wait_time)
                except Exception as e:
                    print("发送错误:", e)
                    windows = self.driver.window_handles
                    self.driver.switch_to.window(windows[0])

    # 专利线索-三种类型
    def patent_clue_1_3(self):
        all_clue_type = [u'无效证据检索', u'专利无效宣告', u'专利无效答辩']
        for clue_type in all_clue_type:
            try:
                if self.dboperate.is_member(self.db, clue_type):
                    locator = (By.XPATH, "(.//div[@class='fl isnaMar'])[2]")
                    WebDriverWait(self.driver, 30, 0.5).until(
                        EC.element_to_be_clickable(locator))
                    aa = self.driver.find_element_by_xpath(
                        "(.//div[@class='fl isnaMar'])[1]")
                    ActionChains(self.driver).move_to_element(aa).perform()
                    self.driver.find_element_by_link_text(clue_type).click()
                    # 切换至新窗口
                    windows = self.driver.window_handles
                    self.driver.switch_to.window(windows[-1])

                    # 随机选择一个类型
                    num = random.randint(1, 3)
                    print(num)
                    self.driver.find_element_by_xpath(
                        "(.//div[@class='ui-apply-zlsq']/div/ul/li[{}]/a)".
                        format(num)).click()
                    time.sleep(0.5)
                    case_type = self.driver.find_element_by_xpath(
                        "(.//div[@class='ui-apply-zlsq']/div/ul/li[{}]/a)".
                        format(num)).text
                    time.sleep(0.5)

                    # 输入联系方式/联系人
                    case_name = self.driver.find_element_by_xpath(
                        "(.//div[@class='ui-apply-tit']//h3)").text
                    if self.add_clue:
                        self.phone = self.make_phone()
                        self.driver.find_element_by_id(
                            "consult_phone").send_keys(self.phone)
                    self.driver.find_element_by_id(
                        "consult_contact").send_keys(case_name + "-" +
                                                     case_type)

                    # 提交需求
                    self.driver.find_element_by_xpath(
                        "(.//div[@class='ui-zlsq-gwc']/a)[1]").click()
                    time.sleep(0.5)
                    # 判断是否成功推送
                    res = self.check_rasult()
                    self.driver.find_element_by_link_text(u'确定').click()
                    self.driver.close()
                    self.driver.switch_to.window(windows[0])

                    self.dboperate.del_elem(self.db, clue_type)
                    back_parm = (self.phone, case_name, res)
                    self.row = self.row + 1
                    self.save_clue_log(back_parm)
                    if self.wait:
                        print("休息{}s...".format(self.wait_time))
                        time.sleep(self.wait_time)
            except Exception as e:
                print("发送错误:", e)
                windows = self.driver.window_handles
                self.driver.switch_to.window(windows[0])

    # 海外国家专利申请-其他国家
    def patent_clue_1_4_1(self):
        clue_type = u'海外国家专利申请-其他国家'
        if self.dboperate.is_member(self.db, clue_type):
            try:
                locator = (By.XPATH, "(.//div[@class='fl isnaMar'])[2]")
                WebDriverWait(self.driver, 30,
                              0.5).until(EC.element_to_be_clickable(locator))
                aa = self.driver.find_element_by_xpath(
                    "(.//div[@class='fl isnaMar'])[1]")
                ActionChains(self.driver).move_to_element(aa).perform()
                self.driver.find_element_by_link_text(u'海外国家专利申请').click()
                # 切换至新窗口
                windows = self.driver.window_handles
                self.driver.switch_to.window(windows[-1])

                # 选择国家,范围 1-6
                self.driver.find_element_by_xpath(
                    "(.//li[@origin='92'])").click()
                time.sleep(0.5)
                # 选择类型范围  1:71-72;2:81-82;3:91-93;4:101-103;5:111-113;6:121-122
                # self.driver.find_element_by_xpath("(.//li[@pt='71'])").click()
                # time.sleep(0.5)

                # 输入联系方式/联系人
                case_name = self.driver.find_element_by_xpath(
                    "(.//div[@class='ui-apply-tit']//h3)").text
                if self.add_clue:
                    self.phone = self.make_phone()
                    self.driver.find_element_by_id("consult_phone").send_keys(
                        self.phone)
                self.driver.find_element_by_id("consult_contact").send_keys(
                    case_name)

                # 提交需求
                self.driver.find_element_by_xpath(
                    "(.//div[@class='ui-zlsq-gwc']/a)[1]").click()
                time.sleep(0.5)
                # 判断是否成功推送
                res = self.check_rasult()
                self.driver.find_element_by_link_text(u'确定').click()
                self.driver.close()
                self.driver.switch_to.window(windows[0])
                self.dboperate.del_elem(self.db, clue_type)
                back_parm = (self.phone, case_name, res)
                self.row = self.row + 1
                self.save_clue_log(back_parm)
                if self.wait:
                    print("休息{}s...".format(self.wait_time))
                    time.sleep(self.wait_time)
            except Exception as e:
                print("发送错误:", e)
                windows = self.driver.window_handles
                self.driver.switch_to.window(windows[0])

    # 海外国家专利申请
    def patent_clue_1_4_2(self):
        clue_type = u'海外国家专利申请'
        if self.dboperate.is_member(self.db, clue_type):
            try:
                locator = (By.XPATH, "(.//div[@class='fl isnaMar'])[2]")
                WebDriverWait(self.driver, 30,
                              0.5).until(EC.element_to_be_clickable(locator))
                aa = self.driver.find_element_by_xpath(
                    "(.//div[@class='fl isnaMar'])[1]")
                ActionChains(self.driver).move_to_element(aa).perform()
                self.driver.find_element_by_link_text(u'海外国家专利申请').click()
                # 切换至新窗口
                windows = self.driver.window_handles
                self.driver.switch_to.window(windows[-1])

                # 随机选择一个国家
                num = random.randint(1, 6)
                print(num)
                self.driver.find_element_by_xpath(
                    "(.//li[@t='{}'])".format(num)).click()
                nation = self.driver.find_element_by_xpath(
                    "(.//li[@t='{}'])".format(num)).text
                time.sleep(0.5)
                # 选择类型 1:71-72;2:81-82;3:91-93;4:101-103;5:111-113;6:121-122
                nation_type = {}
                nation_type.update({
                    "1": [71, 72],
                    "2": [81, 82],
                    "3": [91, 92, 93],
                    "4": [101, 102, 103],
                    "5": [111, 112, 113],
                    "6": [121, 122]
                })
                # 随机选择一个业务类型
                type_num = nation_type["{}".format(num)]
                self.driver.find_element_by_xpath("(.//li[@pt='{}'])".format(
                    random.choice(type_num))).click()
                time.sleep(0.5)
                name = self.driver.find_element_by_xpath(
                    "(.//li[@pt='{}'])".format(random.choice(type_num))).text
                # 输入联系方式/联系人
                case_name = self.driver.find_element_by_xpath(
                    "(.//div[@class='ui-apply-tit']//h3)").text
                if self.add_clue:
                    self.phone = self.make_phone()
                    self.driver.find_element_by_id("consult_phone").send_keys(
                        self.phone)
                self.driver.find_element_by_id("consult_contact").send_keys(
                    case_name + "-" + nation + "-" + name)

                # 提交需求
                self.driver.find_element_by_xpath(
                    "(.//div[@class='ui-zlsq-gwc']/a)[1]").click()
                time.sleep(0.5)
                # 判断是否成功推送
                res = self.check_rasult()
                self.driver.find_element_by_link_text(u'确定').click()
                self.driver.close()
                self.driver.switch_to.window(windows[0])
                self.dboperate.del_elem(self.db, clue_type)
                back_parm = (self.phone, case_name, res)
                self.row = self.row + 1
                self.save_clue_log(back_parm)
                if self.wait:
                    print("休息{}s...".format(self.wait_time))
                    time.sleep(self.wait_time)
            except Exception as e:
                print("发送错误:", e)
                windows = self.driver.window_handles
                self.driver.switch_to.window(windows[0])

    # logo设计
    def patent_clue_2(self):
        clue_type = u'logo设计'
        if self.dboperate.is_member(self.db, clue_type):
            try:
                locator = (By.XPATH, "(.//div[@class='fl isnaMar'])[2]")
                WebDriverWait(self.driver, 30,
                              0.5).until(EC.element_to_be_clickable(locator))
                aa = self.driver.find_element_by_xpath(
                    "(.//div[@class='fl isnaMar'])[2]")
                ActionChains(self.driver).move_to_element(aa).perform()
                self.driver.find_element_by_link_text(u'logo设计').click()
                # 切换至新窗口
                windows = self.driver.window_handles
                self.driver.switch_to.window(windows[-1])

                # 输入联系方式/联系人
                case_name = self.driver.find_element_by_xpath(
                    "(.//div[@class='ui-apply-tit']/h3)").text
                if self.add_clue:
                    self.phone = self.make_phone()

                    self.driver.find_element_by_id("consult_phone").send_keys(
                        self.phone)
                self.driver.find_element_by_id("consult_contact").send_keys(
                    case_name)

                # 提交需求
                self.driver.find_element_by_xpath(
                    "(.//div[@class='ui-zlsq-gwc']/a)[1]").click()
                time.sleep(0.5)
                # 判断是否成功推送
                res = self.check_rasult()
                self.driver.find_element_by_link_text(u'确定').click()
                self.driver.close()
                self.driver.switch_to.window(windows[0])

                self.dboperate.del_elem(self.db, clue_type)
                back_parm = (self.phone, case_name, res)
                self.row = self.row + 1
                self.save_clue_log(back_parm)
                if self.wait:
                    print("休息{}s...".format(self.wait_time))
                    time.sleep(self.wait_time)
            except Exception as e:
                print("发送错误:", e)
                windows = self.driver.window_handles
                self.driver.switch_to.window(windows[0])

    # 创新线索14个
    def patent_clue_5(self):
        all_clue_type = [
            u'双软认证', u'ISO9001质量管理体系认证', u'软件产品登记测试报告', u'科技成果评价', u'贯标申请服务',
            u'知识产权保护', u'专利风险预警', u'专利侵权对抗', u'无效/异议提起', u'合同审核', u'知识产权维权',
            u'咨询分析报告', u'知识产权运营', u'知识产权顾问'
        ]
        for clue_type in all_clue_type:
            if self.dboperate.is_member(self.db, clue_type):
                try:
                    locator = (By.XPATH, "(.//div[@class='fl isnaMar'])[2]")
                    WebDriverWait(self.driver, 30, 0.5).until(
                        EC.element_to_be_clickable(locator))
                    aa = self.driver.find_element_by_xpath(
                        "(.//div[@class='fl isnaMar'])[5]")
                    ActionChains(self.driver).move_to_element(aa).perform()
                    self.driver.find_element_by_link_text(clue_type).click()
                    # 切换至新窗口
                    windows = self.driver.window_handles
                    self.driver.switch_to.window(windows[-1])

                    # 输入联系方式/联系人
                    case_name = self.driver.find_element_by_xpath(
                        "(.//div[@class='ui-apply-tit']/h3)").text
                    if self.add_clue:
                        self.phone = self.make_phone()
                        self.driver.find_element_by_id(
                            "consult_phone").send_keys(self.phone)
                    self.driver.find_element_by_id(
                        "consult_contact").send_keys(case_name)

                    # 提交需求
                    self.driver.find_element_by_xpath(
                        "(.//div[@class='ui-zlsq-gwc']/a)[1]").click()
                    time.sleep(0.5)
                    # 判断是否成功推送
                    res = self.check_rasult()
                    self.driver.find_element_by_link_text(u'确定').click()
                    self.driver.close()
                    self.driver.switch_to.window(windows[0])
                    self.dboperate.del_elem(self.db, clue_type)
                    back_parm = (self.phone, case_name, res)
                    self.row = self.row + 1
                    self.save_clue_log(back_parm)
                    if self.wait:
                        print("休息{}s...".format(self.wait_time))
                        time.sleep(self.wait_time)
                except Exception as e:
                    print("发送错误:", e)
                    windows = self.driver.window_handles
                    self.driver.switch_to.window(windows[0])

    # 软件开发
    def patent_clue_5_1(self):
        all_clue_type = [u'软件开发']
        for clue_type in all_clue_type:
            if self.dboperate.is_member(self.db, clue_type):
                try:
                    locator = (By.XPATH, "(.//div[@class='fl isnaMar'])[2]")
                    WebDriverWait(self.driver, 30, 0.5).until(
                        EC.element_to_be_clickable(locator))
                    aa = self.driver.find_element_by_xpath(
                        "(.//div[@class='fl isnaMar'])[5]")
                    ActionChains(self.driver).move_to_element(aa).perform()
                    self.driver.find_element_by_link_text(clue_type).click()
                    # 切换至新窗口
                    windows = self.driver.window_handles
                    self.driver.switch_to.window(windows[-1])

                    # 随机选择一个类型
                    num = random.randint(1, 5)
                    text = "软件开发需求"
                    self.driver.find_element_by_class_name(
                        "soft-textarea").send_keys(text)
                    # demand = self.driver.find_element_by_xpath("(.//textarea)").text

                    self.driver.find_element_by_xpath(
                        "(.//ul[@class='soft-optaion fl']/label[{}]/li)".
                        format(num)).click()
                    time.sleep(0.5)
                    price = self.driver.find_element_by_xpath(
                        "(.//ul[@class='soft-optaion fl']/label[{}]/li)".
                        format(num)).text
                    time.sleep(0.5)

                    # 输入联系方式/联系人
                    case_name = self.driver.find_element_by_xpath(
                        "(.//div[@class='ui-apply-tit']//h3)").text
                    if self.add_clue:
                        self.phone = self.make_phone()
                        self.driver.find_element_by_id(
                            "consult_phone").send_keys(self.phone)
                    self.driver.find_element_by_id("yourname").send_keys(
                        case_name + text + "-" + price)

                    # 提交需求
                    self.driver.find_element_by_xpath(
                        "(.//div[@class='ui-zlsq-gwc']/a)[1]").click()
                    time.sleep(0.5)

                    # 判断是否成功推送
                    res = self.check_rasult()
                    self.driver.find_element_by_link_text(u'确定').click()
                    self.driver.close()
                    self.driver.switch_to.window(windows[0])
                    self.dboperate.del_elem(self.db, clue_type)
                    back_parm = (self.phone, case_name, res, text, price)
                    self.row = self.row + 1
                    self.save_clue_log(back_parm)
                    if self.wait:
                        print("休息{}s...".format(self.wait_time))
                        time.sleep(self.wait_time)
                except Exception as e:
                    print("发送错误:", e)
                    windows = self.driver.window_handles
                    self.driver.switch_to.window(windows[0])
コード例 #12
0
                    self.dboperate.del_elem(self.db, clue_type)
                    back_parm = (self.phone, case_name, res, text, price)
                    self.row = self.row + 1
                    self.save_clue_log(back_parm)
                    if self.wait:
                        print("休息{}s...".format(self.wait_time))
                        time.sleep(self.wait_time)
                except Exception as e:
                    print("发送错误:", e)
                    windows = self.driver.window_handles
                    self.driver.switch_to.window(windows[0])


if __name__ == "__main__":
    # 添加测试内容
    res = DbOperate()
    clue_db = "clue"
    clue_1_1 = [u'专利布局规划', u'研发立项支持']
    clue_1_2 = [u'新产品风险预警(FTO)', u'侵权风险分析', u'行业专利导航']
    clue_1_3 = [u'无效证据检索', u'专利无效宣告', u'专利无效答辩']
    clue_1_4 = [u'海外国家专利申请-其他国家', u'海外国家专利申请']
    clue_2 = [u'logo设计']
    clue_5 = [u'双软认证', u'咨询分析报告', u'知识产权运营', u'知识产权顾问']
    clue_5_1 = [u'软件开发']

    # all_clue_type = clue_1_1 + clue_1_2 + clue_1_3 + clue_1_4+clue_2+clue_5+clue_5_1
    all_clue_type = clue_1_3
    res.add(clue_db, all_clue_type)
    qq = Execute()
    qq.patent_clue_1_3()
    # qq.patent_clue_1_2()
コード例 #13
0
ファイル: copyright.py プロジェクト: DongDong-123/zgg_test
class Execute(object, metaclass=FunctionName):
    def __init__(self):
        self.common = Common()
        self.timetemp = time.strftime("%Y-%m-%d-%H-%M-%S",
                                      time.localtime())  # 存储Excel表格文件名编号
        self.dboperate = DbOperate()
        self.db = "copyright"

    # 执行下单
    def execute_function(self, callback):
        try:
            eval("self.{}()".format(callback))
        except Exception as e:
            print("错误信息:", e)
            self.common.write_error_log(callback)
            time.sleep(0.5)
            self.common.write_error_log(str(e))

    # 计算机软件著作权登记
    def copyright_computer_software_01(self):
        all_type = [u'计算机作品著作权登记']
        type_code = ["computer"]
        for index, copyright_type in enumerate(all_type):
            if self.dboperate.exists(type_code[index]):
                try:
                    locator = (By.XPATH,
                               "//div[@class='isnav-first']/div[1]/h2")
                    WebDriverWait(self.common.driver, 30, 0.5).until(
                        EC.element_to_be_clickable(locator))
                    aa = self.common.driver.find_element_by_xpath(
                        "(.//div[@class='fl isnaMar'])[3]")
                    ActionChains(
                        self.common.driver).move_to_element(aa).perform()
                    self.common.driver.find_element_by_link_text(
                        copyright_type).click()
                    # 切换至新窗口
                    self.common.windows = self.common.driver.window_handles
                    self.common.driver.switch_to_window(
                        self.common.windows[-1])
                    # 服务类型:
                    for num in range(1, 7):
                        if self.dboperate.is_member(type_code[index], num):
                            self.common.driver.find_element_by_xpath(
                                "//ul[@p='232']/li[{}]/a".format(num)).click()
                            # 数量加减
                            # self.common.number_add()
                            # self.common.number_minus()
                            time.sleep(0.5)
                            while not self.common.driver.find_element_by_id(
                                    "totalfee").is_displayed():
                                time.sleep(0.5)
                            # 获取详情页 价格
                            detail_price = self.common.driver.find_element_by_xpath(
                                "(.//div[@class='sames']//label[@id='totalfee'])"
                            ).text
                            print("详情页价格", detail_price)

                            self.common.apply_now()
                            case_name, case_number, case_price, totalprice = self.common.commit_order(
                            )
                            all_info = [
                                case_name, case_number, detail_price,
                                case_price, totalprice
                            ]
                            self.common.row = self.common.row + 1
                            time.sleep(0.5)
                            pay_totalprice = self.common.pay(
                                self.common.windows)
                            all_info.append(pay_totalprice)
                            print(all_info, pay_totalprice)
                            if float(all_info[2]) == float(all_info[3]) and float(all_info[2]) == float(pay_totalprice) \
                                    and float(all_info[4]) == float(all_info[2]):
                                status = 'True'
                            else:
                                status = "False"
                            all_info.append(status)
                            self.common.excel_number(all_info)
                            time.sleep(1)
                            self.common.driver.back()
                            self.common.driver.back()
                            self.common.driver.back()
                            screen_name = "_".join(
                                [case_name, case_number, case_price])
                            self.common.qr_shotscreen(screen_name)
                            self.common.closed_windows(1)
                            self.dboperate.del_elem(type_code[index], num)
                except Exception as e:
                    print(e)
                    self.common.driver.switch_to_window(self.common.windows[0])
                self.common.closed_windows(0)
        time.sleep(1)

    # 美术作品著作权登记-30日
    def copyright_art_works_01(self):
        all_type = [u'美术作品著作权登记']
        type_code = ["art"]
        for index, copyright_type in enumerate(all_type):
            if self.dboperate.exists(type_code[index]):
                try:
                    locator = (By.XPATH,
                               "//div[@class='isnav-first']/div[1]/h2")
                    WebDriverWait(self.common.driver, 30, 0.5).until(
                        EC.element_to_be_clickable(locator))
                    aa = self.common.driver.find_element_by_xpath(
                        "(.//div[@class='fl isnaMar'])[3]")
                    ActionChains(
                        self.common.driver).move_to_element(aa).perform()
                    self.common.driver.find_element_by_link_text(
                        copyright_type).click()
                    # 切换至新窗口
                    self.common.windows = self.common.driver.window_handles
                    self.common.driver.switch_to_window(
                        self.common.windows[-1])
                    for num in range(1, 7):
                        if self.dboperate.is_member(type_code[index], num):
                            self.common.driver.find_element_by_xpath(
                                "//ul[@p='107538']/li[{}]/a".format(
                                    num)).click()
                            # 数量加减
                            # self.common.number_add()
                            # # self.common.number_minus()
                            time.sleep(0.5)
                            while not self.common.driver.find_element_by_id(
                                    "totalfee").is_displayed():
                                time.sleep(0.5)
                            # 获取详情页 价格
                            detail_price = self.common.driver.find_element_by_xpath(
                                "(.//div[@class='sames']//label[@id='totalfee'])"
                            ).text
                            print("详情页价格", detail_price)

                            self.common.apply_now()
                            case_name, case_number, case_price, totalprice = self.common.commit_order(
                            )

                            all_info = [
                                case_name, case_number, detail_price,
                                case_price, totalprice
                            ]
                            self.common.row = self.common.row + 1
                            time.sleep(0.5)

                            pay_totalprice = self.common.pay(
                                self.common.windows)
                            all_info.append(pay_totalprice)
                            print(all_info, pay_totalprice)
                            if float(all_info[2]) == float(all_info[3]) and float(all_info[2]) == float(pay_totalprice)\
                                    and float(all_info[4]) == float(all_info[2]):
                                status = 'True'
                            else:
                                status = "False"
                            all_info.append(status)
                            self.common.excel_number(all_info)
                            time.sleep(1)
                            self.common.driver.back()
                            self.common.driver.back()
                            self.common.driver.back()
                            screen_name = "_".join(
                                [case_name, case_number, case_price])
                            self.common.qr_shotscreen(screen_name)
                            self.common.closed_windows(1)
                            self.dboperate.del_elem(type_code[index], num)
                except Exception as e:
                    print(e)
                    self.common.driver.switch_to_window(self.common.windows[0])
                self.common.closed_windows(0)
        time.sleep(1)

    # 文字作品著作权登记
    def copyright_writings_01(self):
        # 选择文字作品著作权登记
        all_type = [
            u'汇编作品著作权登记', u'文字作品著作权登记', u'摄影作品著作权登记', u'电影作品著作权登记',
            u'音乐作品著作权登记', u'曲艺作品著作权登记'
        ]
        type_code = [
            "compile", "word", "photography", "film", "music", "drama"
        ]
        for index, copyright_type in enumerate(all_type):
            if self.dboperate.exists(type_code[index]):
                try:
                    locator = (By.XPATH,
                               "//div[@class='isnav-first']/div[1]/h2")
                    WebDriverWait(self.common.driver, 30, 0.5).until(
                        EC.element_to_be_clickable(locator))
                    aa = self.common.driver.find_element_by_xpath(
                        "(.//div[@class='fl isnaMar'])[3]")
                    ActionChains(
                        self.common.driver).move_to_element(aa).perform()
                    self.common.driver.find_element_by_link_text(
                        copyright_type).click()
                    # 切换至新窗口
                    self.common.windows = self.common.driver.window_handles
                    self.common.driver.switch_to_window(
                        self.common.windows[-1])
                    # 案件类型:
                    for num in range(1, 7):
                        if self.dboperate.is_member(type_code[index], num):
                            self.common.driver.find_element_by_xpath(
                                "//ul[@id='ulType']/li[{}]/a".format(
                                    num)).click()
                            # 数量加减
                            # self.common.number_add()
                            # # self.common.number_minus()
                            time.sleep(0.5)
                            while not self.common.driver.find_element_by_id(
                                    "totalfee").is_displayed():
                                time.sleep(0.5)
                            # 获取详情页 价格
                            detail_price = self.common.driver.find_element_by_xpath(
                                "(.//div[@class='sames']//label[@id='totalfee'])"
                            ).text
                            print("详情页价格", detail_price)

                            self.common.apply_now()
                            case_name, case_number, case_price, totalprice = self.common.commit_order(
                            )

                            all_info = [
                                case_name, case_number, detail_price,
                                case_price, totalprice
                            ]
                            self.common.row = self.common.row + 1
                            time.sleep(0.5)

                            pay_totalprice = self.common.pay(
                                self.common.windows)

                            all_info.append(pay_totalprice)
                            print(all_info, pay_totalprice)
                            if float(all_info[2]) == float(all_info[3]) and float(all_info[2]) == float(pay_totalprice) \
                                    and float(all_info[4]) == float(all_info[2]):
                                status = 'True'
                            else:
                                status = "False"
                            all_info.append(status)
                            self.common.excel_number(all_info)

                            time.sleep(1)
                            self.common.driver.back()
                            self.common.driver.back()
                            self.common.driver.back()
                            screen_name = "_".join(
                                [case_name, case_number, case_price])
                            self.common.qr_shotscreen(screen_name)
                            self.common.closed_windows(1)
                            self.dboperate.del_elem(type_code[index], num)
                except Exception as e:
                    print(e)
                    self.common.driver.switch_to_window(self.common.windows[0])
                self.common.closed_windows(0)
        time.sleep(1)
コード例 #14
0
class Execute(object, metaclass=FunctionName):
    def __init__(self):
        self.common = Common()
        # 登录
        self.driver = self.common.driver
        # Excel写入
        self.row = 0
        self.workbook = xlwt.Workbook(encoding='utf-8')
        self.booksheet = self.workbook.add_sheet('Sheet1')
        self.timetemp = time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime())  # 存储Excel表格文件名编号
        # 每个案件的数量
        self.number = 1
        self.report_path = ReadConfig().save_report()
        self.case_count = FunctionName.get_count
        self.excel_number(("案件名称", "案件号", "详情页价格", "下单页价格", "下单页总价格", "支付页总价格", "价格状态"))
        self.dboperate = DbOperate()
        self.windows = None
        self.db = "case"


    # 增加案件数量
    def number_add(self):
        if self.number > 1:
            for i in range(self.number):
                self.driver.find_element_by_xpath("//a[@class='add']").click()
        else:
            self.driver.find_element_by_xpath("//a[@class='add']").click()

    # 减少案件数量至1
    def number_minus(self):
        while self.number > 1:
            self.driver.find_element_by_xpath("//a[@class='jian']").click()

    # 执行下单
    def execute_function(self, callback):
        try:
            eval("self.{}()".format(callback))
        except Exception as e:
            print("错误信息:", e)
            self.write_error_log(callback)
            time.sleep(0.5)
            self.write_error_log(str(e))

    def write_error_log(self, info):
        error_log_path = os.path.join(self.report_path,
                                      "error_log_{}.log".format(time.strftime("%Y-%m-%d", time.localtime())))
        with open(error_log_path, "a", encoding="utf-8") as f:
            f.write("{}: ".format(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())) + info + "\n")

    # 立即申请
    def apply_now(self):
        self.driver.find_element_by_xpath("//div[@class='ui-zlsq-gwc']/a[1]").click()

    # 处理价格字符
    def process_price(self, price):
        if "¥" in price:
            price = price.replace("¥", '')
        return price

    # 提交订单
    def commit_order(self):
        locator = (By.XPATH, "(//parent::li[div[@class='selected-b']])[1]")
        WebDriverWait(self.driver, 30, 1).until(EC.element_to_be_clickable(locator))
        case_name = self.driver.find_element_by_xpath("//tr[@class='tr-comm']/td[1]").text
        case_number = self.driver.find_element_by_xpath("//tr[@class='tr-comm']/td[3]").text
        case_price = self.driver.find_element_by_xpath("//tr[@class='tr-comm']/td[4]").text
        totalprice = self.driver.find_element_by_xpath("//div[@class='totalPrice']/div/b").text
        totalprice = self.process_price(totalprice)
        self.driver.find_element_by_id('lnkPay').click()
        # 返回价格
        return case_name, case_number, case_price, totalprice

    # 支付
    def pay(self, windows):
        pay_totalprice = self.driver.find_element_by_xpath("//div[@class='totalPrice']/div/b").text
        self.driver.find_element_by_id('lnkPay').click()
        self.driver.switch_to_window(windows[-1])
        self.driver.find_element_by_xpath("//div[@class='wczfBtn']/input").click()
        return self.process_price(pay_totalprice)

    # 关闭窗口
    def closed_windows(self):
        print("=================0==============")
        print(self.windows)
        n = len(self.windows)
        while n > 1:
            print('windows1', self.windows)
            self.driver.switch_to_window(self.windows[-1])
            print("===================1=============")
            self.driver.close()
            del self.windows[-1]
            n -= 1
            self.driver.switch_to_window(self.windows[0])
            print('windows2', self.windows)
            print("=====================2=============")

    # 存储案件类型,案件号
    def excel_number(self, infos):
        # 获取案件名称、案件号
        if infos:
            n = 0
            for info in infos:
                self.booksheet.write(self.row, n, info)
                self.booksheet.col(n).width = 300 * 28
                n += 1
            path = os.path.join(self.report_path, "report_{}.xls".format(self.timetemp))
            self.workbook.save(path)

    # =======================业务类型=================================
    # 国内商标
    def trademark_adviser_register(self):
        all_type = [u'专属顾问注册', u'专属加急注册', u'专属双享注册', u'专属担保注册']
        for trademark_type in all_type:
            if self.dboperate.is_member(self.db, trademark_type):
                try:
                    locator = (By.XPATH, "(.//div[@class='fl isnaMar'])[2]")
                    WebDriverWait(self.driver, 30, 0.5).until(EC.element_to_be_clickable(locator))
                    aa = self.driver.find_element_by_xpath("(.//div[@class='fl isnaMar'])[2]")
                    ActionChains(self.driver).move_to_element(aa).perform()
                    self.driver.find_element_by_link_text(trademark_type).click()
                    # 切换至新窗口
                    windows = self.driver.window_handles
                    self.driver.switch_to_window(windows[-1])

                    self.apply_now()
                    # 切换至选择商标分类页面
                    self.windows = self.driver.window_handles
                    self.driver.switch_to_window(self.windows[-1])
                    # 双滚动条有问题,底部的无法点击
                    # num = random.randint(1, 30)
                    num = 35
                    print("num", num)
                    time.sleep(1)
                    target = self.driver.find_element_by_xpath(
                        ".//ul[@class='statuslist']/li[{}]".format(num))
                    self.driver.execute_script("arguments[0].scrollIntoView();", target)
                    time.sleep(1)
                    self.driver.find_element_by_xpath(".//ul[@class='statuslist']/li[{}]".format(45)).click()

                    time.sleep(0.5)
                    while not self.driver.find_element_by_id("costesNum").is_displayed():
                        time.sleep(0.5)
                    # 获取详情页 价格
                    # detail_price = self.driver.find_element_by_xpath("(.//div[@class='info-checkedtop']/p/span)").text
                    detail_price = self.driver.find_element_by_xpath("(.//div[@class='bottomin']/p[1]/span)").text
                    detail_price = self.process_price(detail_price)

                    print("详情页价格", detail_price)
                    self.driver.find_element_by_xpath(".//div[@id='bottombg']/div/span").click()

                    case_name, case_number, case_price, totalprice = self.commit_order()
                    all_info = [case_name, case_number, detail_price, case_price, totalprice]
                    self.row = self.row + 1
                    time.sleep(0.5)
                    pay_totalprice = self.pay(self.windows)
                    all_info.append(pay_totalprice)
                    print(all_info, pay_totalprice)
                    if float(all_info[2]) == float(all_info[3]) and float(all_info[2]) == float(pay_totalprice) and \
                            float(all_info[4]) == float(all_info[2]):
                        status = 'True'
                    else:
                        status = "False"
                    all_info.append(status)
                    self.excel_number(all_info)
                    # 删除已执行的类型
                    self.dboperate.del_elem(self.db, trademark_type)
                    time.sleep(1)
                    self.closed_windows()
                except Exception as e:
                    print('错误信息', e)
                    self.driver.switch_to_window(self.windows[0])

    # 国际商标
    def trademark_international(self):
        all_type = [u'美国商标注册', u'日本商标注册', u'韩国商标注册', u'台湾商标注册', u'香港商标注册', u'德国商标注册',
                    u'欧盟商标注册', u'马德里国际商标', u'非洲知识产权组织']
        for international_type in all_type:
            if self.dboperate.is_member(self.db, international_type):
                try:
                    locator = (By.XPATH, ".//div[@class='isnav-first']/div[1]/h2")
                    WebDriverWait(self.driver, 30, 0.5).until(EC.element_to_be_clickable(locator))
                    aa = self.driver.find_element_by_xpath("(.//div[@class='fl isnaMar'])[2]")
                    ActionChains(self.driver).move_to_element(aa).perform()
                    self.driver.find_element_by_link_text(international_type).click()
                    # 切换至新窗口
                    self.windows = self.driver.window_handles
                    self.driver.switch_to_window(self.windows[-1])
                    # 商标分类
                    self.driver.find_element_by_xpath("//a[@class='theme-fl']").click()
                    time.sleep(0.5)
                    self.driver.find_element_by_xpath("//ul[@class='theme-ul']/li[1]/p").click()
                    sleep(0.5)
                    self.driver.find_element_by_xpath("//div[@class='theme-btn']/a[3]").click()
                    time.sleep(0.5)
                    while not self.driver.find_element_by_id("totalfee").is_displayed():
                        time.sleep(0.5)
                    # 获取详情页 价格
                    detail_price = self.driver.find_element_by_xpath(
                        "(.//div[@class='sames']//label[@id='totalfee'])").text
                    print("详情页价格", detail_price)

                    self.apply_now()
                    case_name, case_number, case_price, totalprice = self.commit_order()
                    all_info = [case_name, case_number, detail_price, case_price, totalprice]
                    self.row = self.row + 1
                    time.sleep(0.5)
                    pay_totalprice = self.pay(self.windows)
                    all_info.append(pay_totalprice)
                    print(all_info, pay_totalprice)
                    if float(all_info[2]) == float(all_info[3]) and float(all_info[2]) == float(pay_totalprice) and \
                            float(all_info[4]) == float(all_info[2]):
                        status = 'True'
                    else:
                        status = "False"
                    all_info.append(status)
                    self.excel_number(all_info)
                    self.dboperate.del_elem(self.db, international_type)
                    time.sleep(1)
                    print(self.windows)
                    self.closed_windows()
                except Exception as e:
                    print(e)
                    self.driver.switch_to_window(self.windows[0])

    # 共用部分
    def trademark_famous_brand(self):
        all_type = [u'申请商标更正', u'出具商标注册证明申请', u'补发商标注册证申请', u'商标转让', u'商标注销', u'商标变更', u'商标诉讼', u'证明商标注册',
                    u'集体商标注册', u'驰名商标认定']
        for trademark in all_type:
            if self.dboperate.is_member(self.db, trademark):
                try:
                    locator = (By.XPATH, "(.//div[@class='fl isnaMar'])[2]")
                    WebDriverWait(self.driver, 30, 0.5).until(EC.element_to_be_clickable(locator))
                    aa = self.driver.find_element_by_xpath("(.//div[@class='fl isnaMar'])[2]")
                    ActionChains(self.driver).move_to_element(aa).perform()
                    self.driver.find_element_by_link_text(trademark).click()
                    # 切换至新窗口
                    self.windows = self.driver.window_handles
                    self.driver.switch_to_window(self.windows[-1])
                    while not self.driver.find_element_by_id("totalfee").is_displayed():
                        time.sleep(0.5)
                    # 获取详情页 价格
                    detail_price = self.driver.find_element_by_xpath("(.//div[@class='sames']//label[@id='totalfee'])").text
                    print("详情页价格", detail_price)

                    self.apply_now()
                    case_name, case_number, case_price, totalprice = self.commit_order()
                    all_info = [case_name, case_number, detail_price, case_price, totalprice]
                    self.row = self.row + 1
                    time.sleep(0.5)
                    pay_totalprice = self.pay(self.windows)
                    all_info.append(pay_totalprice)
                    print(all_info, pay_totalprice)
                    if float(all_info[2]) == float(all_info[3]) and float(all_info[2]) == float(pay_totalprice) and \
                            float(all_info[4]) == float(all_info[2]):
                        status = 'True'
                    else:
                        status = "False"
                    all_info.append(status)
                    self.excel_number(all_info)
                    self.dboperate.del_elem(self.db, trademark)
                    time.sleep(1)
                    self.closed_windows()
                except Exception as e:
                    print('错误信息', e)
                    self.driver.switch_to_window(self.windows[0])

        time.sleep(1)

    # 商标驳回复审-(普通,双保)
    def trademark_ordinary_reject(self):
        this_type = u'商标驳回复审'
        if self.dboperate.is_member(self.db, this_type):
            locator = (By.XPATH, ".//div[@class='isnav-first']/div[1]/h2")
            WebDriverWait(self.driver, 30, 0.5).until(EC.element_to_be_clickable(locator))
            aa = self.driver.find_element_by_xpath("(.//div[@class='fl isnaMar'])[2]")
            ActionChains(self.driver).move_to_element(aa).perform()
            self.driver.find_element_by_link_text(this_type).click()
            # 切换至新窗口
            self.windows = self.driver.window_handles
            self.driver.switch_to_window(self.windows[-1])
            # 服务类型
            for num in [1, 2]:
                try:
                    time.sleep(0.5)
                    self.driver.find_element_by_xpath(".//ul[@id='ulType']/li[{}]".format(num)).click()
                    # 数量加减
                    # self.number_add()
                    # # self.number_minus()
                    time.sleep(0.5)
                    while not self.driver.find_element_by_id("totalfee").is_displayed():
                        time.sleep(0.5)
                    # 获取详情页 价格
                    detail_price = self.driver.find_element_by_xpath("(.//div[@class='sames']//label[@id='totalfee'])").text
                    print("详情页价格", detail_price)

                    self.apply_now()
                    case_name, case_number, case_price, totalprice = self.commit_order()
                    all_info = [case_name, case_number, detail_price, case_price, totalprice]
                    self.row = self.row + 1
                    time.sleep(0.5)
                    pay_totalprice = self.pay(self.windows)
                    all_info.append(pay_totalprice)
                    print(all_info, pay_totalprice)
                    if float(all_info[2]) == float(all_info[3]) and float(all_info[2]) == float(pay_totalprice) and \
                            float(all_info[4]) == float(all_info[2]):
                        status = 'True'
                    else:
                        status = "False"
                    all_info.append(status)
                    self.excel_number(all_info)
                    time.sleep(1)
                    self.driver.back()
                    self.driver.back()
                    self.driver.back()
                except Exception as e:
                    print(e)
                    self.driver.switch_to_window(self.windows[1])
            self.closed_windows()
            self.dboperate.del_elem(self.db, this_type)
            time.sleep(1)

    # 商标异议 (异议申请、异议答辩)
    def trademark_objection_apply(self):
        this_type = u'商标异议'
        if self.dboperate.is_member(self.db, this_type):
            locator = (By.XPATH, ".//div[@class='isnav-first']/div[1]/h2")
            WebDriverWait(self.driver, 30, 0.5).until(EC.element_to_be_clickable(locator))
            aa = self.driver.find_element_by_xpath("(.//div[@class='fl isnaMar'])[2]")
            ActionChains(self.driver).move_to_element(aa).perform()
            self.driver.find_element_by_link_text(this_type).click()
            # 切换至新窗口
            self.windows = self.driver.window_handles
            self.driver.switch_to_window(self.windows[-1])
            # 业务方向:异议申请、异议答辩、不予注册复审
            for num in [22721, 22722]:
                try:
                    self.driver.find_element_by_xpath(".//li[@pt='{}']/a".format(num)).click()
                    # 数量加减
                    # self.number_add()
                    # # self.number_minus()
                    while not self.driver.find_element_by_id("totalfee").is_displayed():
                        time.sleep(0.5)
                    # 获取详情页 价格
                    detail_price = self.driver.find_element_by_xpath("(.//div[@class='sames']//label[@id='totalfee'])").text
                    print("详情页价格", detail_price)

                    self.apply_now()
                    case_name, case_number, case_price, totalprice = self.commit_order()
                    all_info = [case_name, case_number, detail_price, case_price, totalprice]
                    self.row = self.row + 1
                    time.sleep(0.5)
                    pay_totalprice = self.pay(self.windows)
                    all_info.append(pay_totalprice)
                    print(all_info, pay_totalprice)
                    if float(all_info[2]) == float(all_info[3]) and float(all_info[2]) == float(pay_totalprice) and \
                            float(all_info[4]) == float(all_info[2]):
                        status = 'True'
                    else:
                        status = "False"
                    all_info.append(status)
                    self.excel_number(all_info)
                    time.sleep(1)
                    self.driver.back()
                    self.driver.back()
                    self.driver.back()
                except Exception as e:
                    print(e)
                    self.driver.switch_to_window(self.windows[1])
            self.closed_windows()
            self.dboperate.del_elem(self.db, this_type)
            time.sleep(1)

    # 商标撤三答辩--(商标撤三申请、商标撤三答辩)
    def trademark_brand_revoke_answer(self):
        this_type = u'商标撤销'
        if self.dboperate.is_member(self.db, this_type):
            locator = (By.XPATH, ".//div[@class='isnav-first']/div[1]/h2")
            WebDriverWait(self.driver, 30, 0.5).until(EC.element_to_be_clickable(locator))
            aa = self.driver.find_element_by_xpath("(.//div[@class='fl isnaMar'])[2]")
            ActionChains(self.driver).move_to_element(aa).perform()
            self.driver.find_element_by_link_text(this_type).click()
            # 切换至新窗口
            self.windows = self.driver.window_handles
            self.driver.switch_to_window(self.windows[-1])
            # 业务方向:商标撤三申请、商标撤三答辩
            for num in range(1, 3):
                try:
                    self.driver.find_element_by_xpath(".//ul[@p='2273']/li[{}]/a".format(num)).click()
                    # 数量加减
                    # self.number_add()
                    # # self.number_minus()
                    time.sleep(0.5)
                    while not self.driver.find_element_by_id("totalfee").is_displayed():
                        time.sleep(0.5)
                    # 获取详情页 价格
                    detail_price = self.driver.find_element_by_xpath("(.//div[@class='sames']//label[@id='totalfee'])").text
                    print("详情页价格", detail_price)

                    self.apply_now()
                    case_name, case_number, case_price, totalprice = self.commit_order()
                    all_info = [case_name, case_number, detail_price, case_price, totalprice]
                    self.row = self.row + 1
                    time.sleep(0.5)
                    pay_totalprice = self.pay(self.windows)
                    all_info.append(pay_totalprice)
                    print(all_info, pay_totalprice)
                    if float(all_info[2]) == float(all_info[3]) and float(all_info[2]) == float(pay_totalprice) and \
                            float(all_info[4]) == float(all_info[2]):
                        status = 'True'
                    else:
                        status = "False"
                    all_info.append(status)
                    self.excel_number(all_info)
                    time.sleep(1)
                    self.driver.back()
                    self.driver.back()
                    self.driver.back()
                except Exception as e:
                    print(e)
                    self.driver.switch_to_window(self.windows[1])
            self.closed_windows()
            self.dboperate.del_elem(self.db, this_type)
            time.sleep(1)

    # 商标无效宣告--(商标无效宣告、商标无效宣告答辩)
    def trademark_brand_invalid_declare(self):
        this_type = u'商标无效'
        if self.dboperate.is_member(self.db, this_type):
            locator = (By.XPATH, ".//div[@class='isnav-first']/div[1]/h2")
            WebDriverWait(self.driver, 30, 0.5).until(EC.element_to_be_clickable(locator))
            aa = self.driver.find_element_by_xpath("(.//div[@class='fl isnaMar'])[2]")
            ActionChains(self.driver).move_to_element(aa).perform()
            self.driver.find_element_by_link_text(this_type).click()
            # 切换至新窗口
            self.windows = self.driver.window_handles
            self.driver.switch_to_window(self.windows[-1])
            # 业务方向:商标无效宣告、商标无效宣告答辩
            for num in range(1, 3):
                try:
                    self.driver.find_element_by_xpath(".//ul[@p='2279']/li[{}]/a".format(num)).click()
                    # 数量加减
                    # self.number_add()
                    # # self.number_minus()

                    time.sleep(0.5)
                    while not self.driver.find_element_by_id("totalfee").is_displayed():
                        time.sleep(0.5)
                    # 获取详情页 价格
                    detail_price = self.driver.find_element_by_xpath("(.//div[@class='sames']//label[@id='totalfee'])").text
                    print("详情页价格", detail_price)

                    self.apply_now()
                    case_name, case_number, case_price, totalprice = self.commit_order()
                    all_info = [case_name, case_number, detail_price, case_price, totalprice]
                    self.row = self.row + 1
                    time.sleep(0.5)
                    pay_totalprice = self.pay(self.windows)
                    all_info.append(pay_totalprice)
                    print(all_info, pay_totalprice)
                    if float(all_info[2]) == float(all_info[3]) and float(all_info[2]) == float(pay_totalprice) and \
                            float(all_info[4]) == float(all_info[2]):
                        status = 'True'
                    else:
                        status = "False"
                    all_info.append(status)
                    self.excel_number(all_info)
                    time.sleep(1)
                    self.driver.back()
                    self.driver.back()
                    self.driver.back()
                except Exception as e:
                    print(e)
                    self.driver.switch_to_window(self.windows[1])
            self.closed_windows()
            self.dboperate.del_elem(self.db, this_type)
            time.sleep(1)

    # 商标续展--(续展申请、宽展申请、补发续展证明)
    def trademark_brand_extension_01(self):
        this_type = u'商标续展'
        if self.dboperate.is_member(self.db, this_type):
            locator = (By.XPATH, ".//div[@class='isnav-first']/div[1]/h2")
            WebDriverWait(self.driver, 30, 0.5).until(EC.element_to_be_clickable(locator))
            aa = self.driver.find_element_by_xpath("(.//div[@class='fl isnaMar'])[2]")
            ActionChains(self.driver).move_to_element(aa).perform()
            self.driver.find_element_by_link_text(this_type).click()
            # 切换至新窗口
            self.windows = self.driver.window_handles
            self.driver.switch_to_window(self.windows[-1])
            # 业务方向:续展申请、宽展申请、补发续展证明
            for num in range(1, 4):
                try:
                    self.driver.find_element_by_xpath(".//ul[@p='2274']/li[{}]/a".format(num)).click()
                    # 数量加减
                    # self.number_add()
                    # # self.number_minus()
                    time.sleep(0.5)
                    while not self.driver.find_element_by_id("totalfee").is_displayed():
                        time.sleep(0.5)
                    # 获取详情页 价格
                    detail_price = self.driver.find_element_by_xpath("(.//div[@class='sames']//label[@id='totalfee'])").text
                    print("详情页价格", detail_price)

                    self.apply_now()
                    case_name, case_number, case_price, totalprice = self.commit_order()
                    all_info = [case_name, case_number, detail_price, case_price, totalprice]
                    self.row = self.row + 1
                    time.sleep(0.5)
                    pay_total_price = self.pay(self.windows)
                    all_info.append(pay_total_price)
                    print(all_info, pay_total_price)
                    if float(all_info[2]) == float(all_info[3]) and float(all_info[2]) == float(pay_total_price) and \
                            float(all_info[4]) == float(all_info[2]):
                        status = 'True'
                    else:
                        status = "False"
                    all_info.append(status)
                    self.excel_number(all_info)
                    time.sleep(1)
                    self.driver.back()
                    self.driver.back()
                    self.driver.back()
                except Exception as e:
                    print(e)
                    self.driver.switch_to_window(self.windows[1])
            self.closed_windows()
            self.dboperate.del_elem(self.db, this_type)
            time.sleep(1)

    # 商标许可备案 --(许可备案、变更(被)许可人名称、许可提前终止)
    def trademark_brand_permit(self):
        this_type = u'商标许可备案'
        if self.dboperate.is_member(self.db, this_type):
            locator = (By.XPATH, ".//div[@class='isnav-first']/div[1]/h2")
            WebDriverWait(self.driver, 30, 0.5).until(EC.element_to_be_clickable(locator))
            aa = self.driver.find_element_by_xpath("(.//div[@class='fl isnaMar'])[2]")
            ActionChains(self.driver).move_to_element(aa).perform()
            self.driver.find_element_by_link_text(this_type).click()
            # 切换至新窗口
            self.windows = self.driver.window_handles
            self.driver.switch_to_window(self.windows[-1])
            # 业务方向:许可备案、变更(被)许可人名称、许可提前终止
            for num in range(1, 4):
                try:
                    self.driver.find_element_by_xpath(".//ul[@p='2278']/li[{}]/a".format(num)).click()
                    # 数量加减
                    # self.number_add()
                    # # self.number_minus()
                    time.sleep(0.5)
                    while not self.driver.find_element_by_id("totalfee").is_displayed():
                        time.sleep(0.5)
                    # 获取详情页 价格
                    detail_price = self.driver.find_element_by_xpath("(.//div[@class='sames']//label[@id='totalfee'])").text
                    print("详情页价格", detail_price)

                    self.apply_now()
                    case_name, case_number, case_price, totalprice = self.commit_order()
                    all_info = [case_name, case_number, detail_price, case_price, totalprice]
                    self.row = self.row + 1
                    time.sleep(0.5)
                    pay_totalprice = self.pay(self.windows)
                    all_info.append(pay_totalprice)
                    print(all_info, pay_totalprice)
                    if float(all_info[2]) == float(all_info[3]) and float(all_info[2]) == float(pay_totalprice) and \
                            float(all_info[4]) == float(all_info[2]):
                        status = 'True'
                    else:
                        status = "False"
                    all_info.append(status)
                    self.excel_number(all_info)
                    time.sleep(1)
                    self.driver.back()
                    self.driver.back()
                    self.driver.back()
                except Exception as e:
                    print(e)
                    self.driver.switch_to_window(self.windows[1])
            self.closed_windows()
            self.dboperate.del_elem(self.db, this_type)
            time.sleep(1)
コード例 #15
0
class Execute(object, metaclass=FunctionName):
    def __init__(self):
        self.common = Common()
        self.timetemp = time.strftime("%Y-%m-%d-%H-%M-%S",
                                      time.localtime())  # 存储Excel表格文件名编号
        self.db = "case"
        self.dboperate = DbOperate()

    # 执行下单
    def execute_function(self, callback):
        try:
            eval("self.{}()".format(callback))
        except Exception as e:
            print("错误信息:", e)
            self.common.write_error_log(callback)
            time.sleep(0.5)
            self.common.write_error_log(str(e))

    # 1 发明专利,实用新型,同日申请
    def patent_invention_normal(self):
        all_type = [u'发明专利', u'实用新型', u'发明新型同日申请']
        type_code = ["invention", "shiyongxinxing", "tongrishenqing"]
        self.common.driver.get("https://m.zgg.com/shenqing/list.html?#zl")
        for index, patent_type in enumerate(all_type):
            if self.dboperate.exists(type_code[index]):
                try:
                    locator = (By.XPATH,
                               "(.//div[@class='list-detail']/ul[5]/li[3]/a)")
                    WebDriverWait(self.common.driver, 30, 0.5).until(
                        EC.element_to_be_clickable(locator))
                    # 专利申请
                    self.common.driver.find_element_by_xpath(
                        ".//div[@class='list-detail']/ul[1]/li[1]/a").click()
                    # 进入分类页面
                    self.common.driver.get(
                        "https://m.zgg.com/shenqing/{}.html?pro=1".format(
                            type_code[index]))

                    for num in range(1, 8):
                        if self.dboperate.is_member(type_code[index], num):
                            print("num:", num)
                            # 服务类型选择,
                            if num < 4:
                                self.common.driver.find_element_by_xpath(
                                    ".//ul[@id='ulType']/li[{}]/a".format(
                                        num)).click()
                            elif num == 4:
                                self.common.driver.find_element_by_xpath(
                                    ".//ul[@id='ulType']/li[1]/a").click()
                                self.common.driver.find_element_by_xpath(
                                    "(.//div[@class='zgg-zlsq-sq-ul']/ul/li[1]/a)[2]"
                                ).click()
                            elif num == 5:
                                self.common.driver.find_element_by_xpath(
                                    ".//ul[@id='ulType']/li[2]/a").click()
                                self.common.driver.find_element_by_xpath(
                                    "(.//div[@class='zgg-zlsq-sq-ul']/ul/li[1]/a)[2]"
                                ).click()
                            elif num == 6:
                                time.sleep(0.5)
                                self.common.driver.find_element_by_xpath(
                                    ".//ul[@id='ulType']/li[3]/a").click()
                                self.common.driver.find_element_by_xpath(
                                    "(.//div[@class='zgg-zlsq-sq-ul']/ul/li[1]/a)[2]"
                                ).click()
                            else:
                                self.common.driver.find_element_by_xpath(
                                    ".//li[@id='liguarantee']/a").click()
                            # 数量加1
                            # self.common.number_add()
                            # 数量减1
                            # # self.common.number_minus()
                            # 判断价格是否加载成功
                            while not self.common.driver.find_element_by_id(
                                    "totalfee").is_displayed():
                                time.sleep(0.5)
                            # 获取详情页 价格
                            detail_price = self.common.driver.find_element_by_xpath(
                                "(.//label[@id='totalfee'])").text
                            print("详情页价格", detail_price)

                            self.common.apply_now()
                            # 获取下单页价格
                            case_name, case_number, case_price, totalprice = self.common.commit_order(
                            )
                            all_info = [
                                case_name, case_number, detail_price,
                                case_price, totalprice
                            ]
                            self.common.row = self.common.row + 1
                            time.sleep(0.5)
                            pay_totalprice = self.common.pay()
                            all_info.append(pay_totalprice)
                            print(all_info, pay_totalprice)
                            if float(all_info[2]) == float(all_info[3]) and float(all_info[2]) == float(
                                    pay_totalprice) and \
                                    float(all_info[4]) == float(all_info[2]):
                                status = 'True'
                            else:
                                status = "False"
                            all_info.append(status)
                            self.common.excel_number(all_info)
                            time.sleep(1)
                            self.common.driver.back()
                            self.common.driver.back()
                            self.common.driver.back()
                            screen_name = "_".join(
                                [case_name, case_number, case_price])
                            # self.common.qr_shotscreen(screen_name)
                            self.dboperate.del_elem(type_code[index], num)
                            print("{}{}执行结束".format(type_code[index], num))
                            time.sleep(1)
                except Exception as e:
                    print(e)
                    self.common.driver.get(
                        "https://m.zgg.com/shenqing/list.html?#zl")
                time.sleep(1)