def search_article(self, article_name): article_list = self.driver.find_elements_by_css_selector( '#app > div.center.shadow-bottom-line > div.center-main.ui-area > div.center-tab-content.clearfix > div.right-main > div > div > div:nth-child(1) > div > ul > li' ) for a in article_list: article_name_css = a.find_element_by_css_selector( '.mi-name-box').text logger.info(article_name_css) if "漫画名称:" + article_name == article_name_css: logger.info(article_name_css) btns = a.find_elements_by_css_selector( 'div > div.bottom-btn-box > div:nth-child(1) > span:nth-child(3)' ) if len(btns) == 0: raise Pang5Exception(f'作品"{article_name}"状态异常') else: logger.info(f'找到{article_name}') btns[0].click() return btn = self.driver.find_element_by_css_selector('.btn-next') if 'disabled' not in btn.get_attribute('class'): logger.info('翻页') btn.click() time.sleep(1) else: raise Pang5Exception(f'用户没有绑定作品 "{article_name}"') self.search_article(article_name)
def process(self, mysql_id): g_mysqlid["mysql_id"] = mysql_id with open_driver(browser=browser) as driver: with track_alert(driver): self.driver = driver # 处理登录 # add_cookie(COOKIE_DOMAIN, driver, COOKIE_FILE) # driver.get('http://www.baidu.com') time.sleep(5) if not self.login_mobile(): status = PLATFORM_STATUS_AUTH_FAIL update_login_status(platform=data[DATA_PLATFORM], platform_username=data[DATA_USERNAME], platform_password=data[DATA_PASSWORD], platform_status=status) raise Pang5Exception('登录失败') # store_cookie(driver, COOKIE_FILE) self.driver.switch_to.default_content() logger.info('登录成功') # 点击章节管理 url = f'http://ac.qq.com/MyComic/chapterList/id/{data[DATA_THIRD_ID]}' logger.info(url) driver.get(url) # self.driver.find_element_by_css_selector(".h_btn_section").click() # 点击新建章节 time.sleep(2) try: self.driver.find_element_by_link_text("新建章节").click() except NoSuchElementException: raise Pang5Exception(f"腾讯动漫作品id({data[DATA_THIRD_ID]})有误") self.publish()
def form(self, driver): ''' 表单处理部分 ''' chapter_name = data[DATA_CHAPTER_NAME] chapter_image = data[DATA_CHAPTER_IMAGE] works_image = data[DATA_WORKS_IMAGE] # input处理readonly js = "document.getElementsByTagName(\"input\").readOnly=false" time.sleep(1) title = driver.find_element_by_css_selector( '#app > div.center.shadow-bottom-line > div.center-main.ui-area > div.center-tab-content.clearfix > div.right-main > div > div > div:nth-child(3) > div > div:nth-child(2) > div.mw-right > div.qd-input-box.mw-comic-name > div.qd-input > input[type="text"]' ) # 正文 title.send_keys(chapter_name) time.sleep(1) # 提示上传 # 上传多个文件 for i in chapter_image: file = driver.find_element_by_css_selector( '#add-section-img > div:nth-child(2) > input') logger.info('上传图片' + i) file.send_keys(i) driver.find_element_by_css_selector('.show-dialog').click() logger.info(f'上传封面图片{works_image}') file = driver.find_element_by_css_selector( '#app > div.center.shadow-bottom-line > div.center-main.ui-area > div.center-tab-content.clearfix > div.right-main > div > div > div:nth-child(3) > div > div.cut-image-dialog.dialog-content > div > div.dialog-middle.clearfix > div.dm-btn-box.clearfix > div > input[type="file"]' ) file.send_keys(works_image) # 判断图片预览是否存在 css = "#app > div.center.shadow-bottom-line > div.center-main.ui-area > div.center-tab-content.clearfix > div.right-main > div > div > div:nth-child(3) > div > div.cut-image-dialog.dialog-content > div > div.dialog-middle.clearfix > div:nth-child(1) > div.dm-cropper-box > img" nodisplay = 'display: none' in driver.find_element_by_css_selector( css).get_attribute('style') if nodisplay: raise Pang5Exception('封面图片不符合要求') for i in range(20): driver.find_element_by_css_selector('.minus-btn').click() driver.find_element_by_css_selector( '#app > div.center.shadow-bottom-line > div.center-main.ui-area > div.center-tab-content.clearfix > div.right-main > div > div > div:nth-child(3) > div > div.cut-image-dialog.dialog-content > div > div.dialog-bottom > span.btn-theme.db-save' ).click() time.sleep(2) self.stop(driver) # 提交 driver.find_element_by_css_selector( '#app > div.center.shadow-bottom-line > div.center-main.ui-area > div.center-tab-content.clearfix > div.right-main > div > div > div:nth-child(3) > div > div.mw-btn-box > span.btn-theme.btn-submit' ).click() time.sleep(2) # 捕获报错信息 hint = driver.execute_script('return window.hint;') if hint: raise Pang5Exception(hint) logger.info('发布成功')
def login(self) -> bool: login_url = get_current_url() self.driver.switch_to.frame('login_ifr') self.driver.find_element_by_css_selector("#switcher_plogin").click() clear_and_send_keys("#u", data[DATA_USERNAME]) time.sleep(1) clear_and_send_keys("#p", data[DATA_PASSWORD]) time.sleep(2) self.driver.find_element_by_css_selector("#login_button").click() time.sleep(3) if get_current_url() != AUTH_OK_URL: logger.info(get_current_url()) status = PLATFORM_STATUS_AUTH_FAIL update_login_status(platform=data[DATA_PLATFORM], platform_username=data[DATA_USERNAME], platform_password=data[DATA_PASSWORD], platform_status=status) raise Pang5Exception("登录异常") ok = get_current_url() != login_url status = PLATFORM_STATUS_AUTH_OK if ok else PLATFORM_STATUS_AUTH_FAIL update_login_status(platform=data[DATA_PLATFORM], platform_username=data[DATA_USERNAME], platform_password=data[DATA_PASSWORD], platform_status=status) return ok
def process(self, mysql_id): g_mysqlid["mysql_id"] = mysql_id with open_driver(browser='firefox') as driver: with track_alert(driver): self.driver = driver # 处理登录 get(MANAGE_URL) if get_current_url() != MANAGE_URL: if not self.login(): raise Pang5Exception('登录失败') logger.info('登录成功') # 根据作品名称点击对应的新建章节 items = driver.find_elements_by_css_selector( '#submission > div.container > ul > li') for item in items: work_name = item.find_element_by_css_selector( 'div.content > h3').text logger.debug(f'发现作品{work_name}') if work_name.strip() == data[DATA_WORKS_NAME].strip(): new_chapter = item.find_element_by_css_selector( 'nav > a:nth-child(2)') new_chapter.click() time.sleep(5) handles = driver.window_handles if len(handles) == 1: logger.error( f'点击创建章节失败 maimeng_series={data[DATA_WORKS_NAME]}') return else: driver.switch_to_window(handles[1]) self.publish()
def weibo_login(self, driver): logger.info('用微博登录') get('https://h5.manhua.163.com/login/form?targetUrl=https%3A%2F%2Fh5.manhua.163.com%2Fsubscribe%3Fsigned_in_callback%3D1' ) driver.find_element_by_css_selector('#sina').click() time.sleep(3) # 一个字母一个字母的输入 # for i in list(data[DATA_USERNAME]): # driver.find_element_by_css_selector('#userId').send_keys(i) # time.sleep(0.5) # time.sleep(2) # for i in list(data[DATA_PASSWORD]): # driver.find_element_by_css_selector('#passwd').send_keys(i) # time.sleep(0.5) driver.find_element_by_css_selector('#userId').send_keys( data[DATA_USERNAME]) time.sleep(0.5) driver.find_element_by_css_selector('#passwd').send_keys( data[DATA_PASSWORD]) time.sleep(0.5) # js = f'document.getElementById("userId").setAttribute("value","{data[DATA_USERNAME]}");' \ # f'document.getElementById("passwd").setAttribute("value","{data[DATA_PASSWORD]}");' # driver.execute_script(js) # import pyautogui # pyautogui.press('f5') # time.sleep(2) # js = 'document.getElementById("userId").focus()' # driver.execute_script(js) # pyautogui.typewrite(data[DATA_USERNAME]) # time.sleep(2) # pyautogui.keyDown('tab') # pyautogui.keyUp('tab') # pyautogui.typewrite(data[DATA_PASSWORD]) # time.sleep(2) # 处理验证码问题 # 火狐浏览器的微博登录是pc端的,所以样式都要用pc端的. # 为什么必须用火狐, 因为只有火狐能对元素截图 captcha_div = driver.find_element_by_css_selector( 'p.oauth_code:nth-child(3)') if captcha_div.is_displayed(): logger.info('有验证码, 截图') captcha_img = captcha_div.find_element_by_css_selector('span img') store_path = f"{CAPTCHAR_PATH}/netEase_{datetime.now().strftime('%Y-%m-%d %H%M%S')}.png" captcha_img.screenshot(store_path) logger.info('调用服务识别') result, ok = image_recog(store_path) if ok: logger.info(f'识别成功,填写{result}') captcha_div.find_element_by_css_selector('input').send_keys( result) else: raise Pang5Exception('验证码识别失败, 请重试') driver.find_element_by_css_selector('a.WB_btn_login').click() # pyautogui.press('enter') time.sleep(3) return 'weibo' in get_current_url()
def mail_login(self, driver, login_username, login_password) -> bool: logger.info('用邮箱登录') if '@' not in login_username: status = PLATFORM_STATUS_AUTH_FAIL update_login_status(platform=data[DATA_PLATFORM], platform_username=data[DATA_USERNAME], platform_password=data[DATA_PASSWORD], platform_status=status) raise Pang5Exception('登录方式是邮箱,但是输入的用户名不是邮箱') get('https://manhua.163.com/') # click('.topbar-meta-user >ul >li:nth-child(1)>.js-login-required') driver.find_element_by_css_selector( '.topbar-meta-user >ul >li:nth-child(1)>.js-login-required').click( ) # driver.find_element_by_css_selector('.sns-mobile').click() driver.switch_to.frame(driver.find_element_by_id("x-URS-iframe")) username = driver.find_element_by_name('email') username.clear() username.send_keys(login_username) password = driver.find_element_by_name('password') password.clear() password.send_keys(login_password) time.sleep(1) driver.find_element_by_id('dologin').click() logger.info('点击登录') time.sleep(2) return True
def publish(self): # 章节名称 self.driver.find_element_by_css_selector( '#create_chapter > div.container > div.inner-container > div:nth-child(1) > div > div.field-input > input[type="text"]' ).send_keys(data[DATA_CHAPTER_NAME]) # # 章节介绍 # self.driver.find_element_by_css_selector( # '#create_chapter > div.container > div.inner-container > div:nth-child(2) > div > div.field-input > textarea').send_keys( # data['maimeng_desp']) # 展示时间 if data[DATA_IS_CLOCK]: self.driver.find_element_by_css_selector( '#create_chapter > div.container > div.inner-container > div:nth-child(3) > div > div.field-input > div > input' ).send_keys(data[DATA_CLOCK_PUBLISH_DATETIME]) # 点击确定 time.sleep(2) # js = '$("button.el-button:nth-child(2)").click();' # self.driver.execute_script(js) # 点击确定按钮居然会变成现在的时间,把他注释掉居然可以了,神奇!!!!!!! # # 备注 # self.driver.find_element_by_css_selector( # '#create_chapter > div.container > div.inner-container > div:nth-child(4) > div > div.field-input > textarea').send_keys( # data['maimeng_comment']) # 漫画原稿 # scroll_to() self.driver.find_element_by_css_selector( '#create_chapter > div.container > div.inner-container > div:nth-child(5) > div > div.field-input > ul > li > img' ).click() img: str = ' '.join(data[DATA_CHAPTER_IMAGE]) logger.info(data) logger.info(img) cmd = f'D:/uploadImg.exe 文件上传 {img}' logger.info(cmd) os.system(cmd) loading = self.driver.find_element_by_css_selector( '#create_chapter > div.container > div.inner-container > div:nth-child(5) > div > div.field-input > ul > div.el-loading-mask' ) start = time.time() MAX_WAIT_SECONDS = 120 while loading.is_displayed(): time.sleep(2) if (time.time() - start) > MAX_WAIT_SECONDS: raise Pang5Exception(f'超过{MAX_WAIT_SECONDS}s图片没有上传完毕') scroll_to() # 同意合同 self.driver.find_element_by_css_selector( '#create_chapter > div:nth-child(2) > label > input[type="checkbox"]' ).click() scroll_to() # 提交审核 time.sleep(2) click_by_actionchains( 'ul.submit > li:nth-child(3) > button.confirm-btn') time.sleep(3)
def process(self, mysql_id): g_mysqlid["mysql_id"] = mysql_id with open_driver() as driver: self.driver = driver with track_alert(driver): LOGIN_USERNAME = data[DATA_USERNAME] LOGIN_PASSWORD = data[DATA_PASSWORD] logger.info(f'用户名{LOGIN_USERNAME}') logger.info(f'密码{LOGIN_PASSWORD}') # 处理登录 if not self.mobile_login(driver, LOGIN_USERNAME, LOGIN_PASSWORD): status = PLATFORM_STATUS_AUTH_FAIL update_login_status(platform=data[DATA_PLATFORM], platform_username=data[DATA_USERNAME], platform_password=data[DATA_PASSWORD], platform_status=status) raise Pang5Exception('登录失败') get(MANAGE_URL) time.sleep(2) cur = get_current_url() if cur != MANAGE_URL: logger.error(MANAGE_URL) status = PLATFORM_STATUS_AUTH_FAIL update_login_status(platform=data[DATA_PLATFORM], platform_username=data[DATA_USERNAME], platform_password=data[DATA_PASSWORD], platform_status=status) raise Pang5Exception("登录失败") logger.info('登录成功') status = PLATFORM_STATUS_AUTH_OK update_login_status(platform=data[DATA_PLATFORM], platform_username=data[DATA_USERNAME], platform_password=data[DATA_PASSWORD], platform_status=status) self.driver.find_element_by_link_text('我的作品').click() self.search_article(data[DATA_WORKS_NAME]) self.form(driver)
def process(self, mysql_id): g_mysqlid["mysql_id"] = mysql_id with open_driver(browser='firefox') as driver: with track_alert(driver): self.driver = driver get(AUTH_OK_URL) if get_current_url() != AUTH_OK_URL: # 登录方式 login_type = data[DATA_LOGIN_TYPE] if login_type in ('', 'mobile', 'email', 'mail', 'username'): login = self.login_mobile elif login_type == 'qq': login = self.login_mobile_qq elif login_type == 'weibo': login = self.login_mobile_weibo else: raise Pang5Exception(f'登录方式不支持{login_type}') if not login(): status = PLATFORM_STATUS_AUTH_FAIL update_login_status( platform=data[DATA_PLATFORM], platform_username=data[DATA_USERNAME], platform_password=data[DATA_PASSWORD], platform_status=status) raise Pang5Exception("登录失败") logger.info('登录成功') logger.info('点击新建章节') new_chapter_url = f'http://comic.user.u17.com/chapter/chapter_add.php?comic_id={data[DATA_THIRD_ID]}' self.driver.get(new_chapter_url) time.sleep(3) if get_current_url() != new_chapter_url: raise Pang5Exception(f'有妖气作品id({data[DATA_THIRD_ID]})有误') self.publish()
def login(self) -> bool: login_url = get_current_url() js = f'''$("#login_username").val("{data[DATA_USERNAME]}"); $("#login_pwd").val("{data[DATA_PASSWORD]}"); $("a.login_btn:nth-child(4)").click();''' self.driver.execute_script(js) time.sleep(3) if get_current_url() != AUTH_OK_URL: status = PLATFORM_STATUS_AUTH_FAIL update_login_status(platform=data[DATA_PLATFORM], platform_username=data[DATA_USERNAME], platform_password=data[DATA_PASSWORD], platform_status=status) raise Pang5Exception("登录失败") status = PLATFORM_STATUS_AUTH_OK update_login_status(platform=data[DATA_PLATFORM], platform_username=data[DATA_USERNAME], platform_password=data[DATA_PASSWORD], platform_status=status) return True
def login(self) -> bool: login_url = get_current_url() clear_and_send_keys(".username-field > input:nth-child(2)", data[DATA_USERNAME]) clear_and_send_keys(".password-field > input:nth-child(2)", data[DATA_PASSWORD]) time.sleep(3) self.driver.find_element_by_css_selector(".login-btn").click() time.sleep(3) if get_current_url() != AUTH_OK_URL: logger.error(get_current_url()) status = PLATFORM_STATUS_AUTH_FAIL update_login_status(platform=data[DATA_PLATFORM], platform_username=data[DATA_USERNAME], platform_password=data[DATA_PASSWORD], platform_status=status) raise Pang5Exception("登录异常") status = PLATFORM_STATUS_AUTH_OK update_login_status(platform=data[DATA_PLATFORM], platform_username=data[DATA_USERNAME], platform_password=data[DATA_PASSWORD], platform_status=status) return True
def publish(self): # 让网站允许Flash # use_flash() # 进入上传章节页面 if not FIRST_CHAPTER: # 有了第一章之后才会出来是否定时发布和发布日期,请提前发布好第一章 if data[DATA_IS_CLOCK] == False: # 定时发布选否 self.driver.find_element_by_css_selector( 'table > tbody > tr:nth-child(2) > td.chapter-publish-time > label:nth-child(2) > input[type="radio"]' ).click() else: # 发布日期 try: # 定时发布选是 self.driver.find_element_by_css_selector( 'table > tbody > tr:nth-child(2) > td.chapter-publish-time > label:nth-child(1) > input[type="radio"]' ).click() self.driver.find_element_by_css_selector( "#chapter_date").send_keys( data[DATA_CLOCK_PUBLISH_DATETIME]) except NoSuchElementException: raise Pang5Exception('定时发布时间页面上处于不能选状态') # 章节名称 clear_and_send_keys("#chapter_title", data[DATA_CHAPTER_NAME]) # 确定修改 self.driver.find_element_by_css_selector("#chapterTitleSubmit").click() # 章节封面 tips_chapter = data[DATA_WORKS_IMAGE] logger.info(tips_chapter) try: self.driver.find_element_by_css_selector("#Filedata").send_keys( tips_chapter) # 点击上传封面 time.sleep(3) self.driver.find_element_by_css_selector('#btn_upload').click() except: logger.info('页面上没有章节封面') time.sleep(3) # 上传章节内容 scroll_to() # self.driver.execute_script('document.querySelectorAll("#button_mid")[0].style.display="block";') # time.sleep(1) # 点击上传按钮 # d = self.driver.find_element_by_css_selector("#create_chapter_tip").location_once_scrolled_into_view # printt(d['x'],d['y']) click_by_pyautogui(CHAPTER_PNG) # click_by_pg(*POSOTION_GREEN_BUTTON) img: str = ' '.join(data[DATA_CHAPTER_IMAGE]) cmd = f'D:/uploadImg.exe 打开 {img}' logger.info(cmd) os.system(cmd) js = 'return $("#uploadProgressBox").text();' while True: percent = self.driver.execute_script(js) time.sleep(4) logger.info(percent) if percent == '100%': break if REAL_PUBLISH: create_url = get_current_url() self.driver.find_element_by_css_selector('#submit_data').click() time.sleep(2) if create_url == get_current_url(): logger.error(f'发布失败') err_msg_eles = self.driver.find_elements_by_css_selector( "#cover_msg > div") if len(err_msg_eles) > 0: err_msg = err_msg_eles[0].text logger.error(err_msg) raise Pang5Exception('发布失败,稍后会重试') logger.info('发布成功')
def process(self, mysql_id): g_mysqlid["mysql_id"] = mysql_id with open_driver(phone_ua=True, browser='firefox') as driver: with track_alert(driver): # 处理登录 login_username = data[DATA_USERNAME] login_password = data[DATA_PASSWORD] logger.info(f'用户名{login_username}') logger.info(f'密码{login_password}') get(MANAGE_URL) if get_current_url() != MANAGE_URL: if data[DATA_LOGIN_TYPE] == 'mobile': self.mobile_login(driver, login_username, login_password) elif data[DATA_LOGIN_TYPE] in ('mail', '', 'email'): self.mail_login(driver, login_username, login_password) elif data[DATA_LOGIN_TYPE] == 'qq': self.qq_login(driver, login_username, login_password) elif data[DATA_LOGIN_TYPE] == 'weibo': self.weibo_login(driver) elif data[DATA_LOGIN_TYPE] == 'weixin': self.weixin_login(driver) else: raise Pang5Exception('暂时不支持您的登录方式') # self.mobile_login(driver) # 登录 # 继续中间页面 logger.info('点击完了登录') get('https://zz.manhua.163.com/') time.sleep(3) if get_current_url() not in [ 'http://zz.manhua.163.com/', 'https://zz.manhua.163.com/' ]: status = PLATFORM_STATUS_AUTH_FAIL update_login_status(platform=data[DATA_PLATFORM], platform_username=data[DATA_USERNAME], platform_password=data[DATA_PASSWORD], platform_status=status) raise Pang5Exception('登录失败') time.sleep(1) logger.info('登录成功') status = PLATFORM_STATUS_AUTH_OK update_login_status(platform=data[DATA_PLATFORM], platform_username=data[DATA_USERNAME], platform_password=data[DATA_PASSWORD], platform_status=status) # try: net_series = driver.find_elements_by_link_text( data[DATA_WORKS_NAME]) if len(net_series) == 0: raise Pang5Exception(f"该用户下没有作品{data[DATA_WORKS_NAME]}") net_series[0].click() time.sleep(1) handles = driver.window_handles time.sleep(1) driver.switch_to_window(handles[-1]) js = "window.scrollTo(0, document.body.scrollHeight)" driver.execute_script(js) driver.find_element_by_css_selector( '#panel1 > div > div > a').click() self.form(driver)
def form(self, driver): ''' 表单处理部分 ''' chapter_name = data[DATA_CHAPTER_NAME] chapter_img = data[DATA_CHAPTER_IMAGE] is_clock = data[DATA_IS_CLOCK] if is_clock: publish_day = data[DATA_CLOCK_PUBLISH_DATETIME].split(' ')[0] pubish_hour = data[DATA_CLOCK_PUBLISH_DATETIME].split( ' ')[1].split(':')[0] min = int( data[DATA_CLOCK_PUBLISH_DATETIME].split(' ')[1].split(':')[1]) if min < 15: publish_min = "00" elif min >= 15 and min < 30: publish_min = "15" elif min >= 30 and min < 45: publish_min = "30" elif min >= 45 and min < 60: publish_min = "45" # input处理readonly js = "$('input').removeAttr('readonly')" time.sleep(1) title = driver.find_element_by_id('title') # 正文 title.send_keys(chapter_name) time.sleep(1) # 提示上传 # 上传多个文件 logger.info('共有图片%d张' % len(chapter_img)) for i, f in enumerate(chapter_img): file = driver.find_element_by_css_selector( '.webuploader-element-invisible') file.send_keys(f) div = driver.find_element_by_css_selector( 'div.episode-upload-throbber') while div.is_displayed(): percent = div.find_element_by_css_selector('div>span').text logger.info(f'图片{i}, 上传进度 {percent}') time.sleep(1) logger.info('上传完成') driver.execute_script(js) # 定时 if is_clock: driver.find_element_by_id('timing_flag').click() autoPublishDate = driver.find_element_by_css_selector( '#timing > div > div.small-4.columns > input[type="text"]') autoPublishDate.clear() # 日期 autoPublishDate.send_keys(publish_day) h = Select( driver.find_element_by_css_selector( '#timing > div > div:nth-child(2) > select')) # 小时 h.select_by_visible_text(pubish_hour) m = Select( driver.find_element_by_css_selector( '#timing > div > div:nth-child(4) > select')) # 分钟 m.select_by_visible_text(publish_min) # 提交 time.sleep(2) # 干掉小女生的遮挡 driver.execute_script('$("#j-epay-warning").remove();') driver.find_element_by_xpath( '/html/body/section[1]/div/div[3]/div/form/div[5]/div[2]/button[2]' ).click() errs = driver.find_elements_by_css_selector( '#firstModal > div.reveal-modal-body.default > div:nth-child(1)') if len(errs) > 0: raise Pang5Exception(errs[0].text) time.sleep(3) logger.info('发布成功')
def weixin_login(self, driver): raise Pang5Exception('暂时不支持微信登录')
def publish(self): logger.info('点击关闭提示') try: scroll_to() self.driver.find_element_by_css_selector( 'a.close_tip:nth-child(2)').click() except: logger.info('没有关闭提示') logger.info('隐藏选择适合自己的字号') try: # js = '$("body > div.font_tip_dialog").hide()' js = 'document.querySelector("body > div.font_tip_dialog").style.display = "none";' self.driver.execute_script(js) except JavascriptException as e: logger.error(e) time.sleep(1) scroll_to_id('chapter_name') logger.info('填写章节名称') clear_and_send_keys("#chapter_name", data[DATA_CHAPTER_NAME]) # 有的没有章节封面 fengmian_eles = self.driver.find_elements_by_css_selector( 'div.bg_cover_box') if len(fengmian_eles) > 0: logger.info('上传封面图片') time.sleep(2) click_by_pyautogui(TITLE_PNG) time.sleep(2) img: str = data[DATA_WORKS_IMAGE] cmd = f'D:/uploadImg.exe 打开 {img}' logger.info(cmd) os.system(cmd) while True: loading_ele = self.driver.find_element_by_css_selector( '.loading_tm > img:nth-child(1)') if not loading_ele.is_displayed(): logger.info('封面上传完毕') break logger.info('封面正在上传中。。。') time.sleep(2) else: logger.info('页面没有章节封面') logger.info('上传章节内容') scroll_to_id('btn_start') click_by_pyautogui(CHAPTER_PNG) img: str = ' '.join(data[DATA_CHAPTER_IMAGE]) cmd = f'D:/uploadImg.exe 打开 {img}' logger.info(cmd) os.system(cmd) time.sleep(2) logger.info('点击开始上传') scroll_to_id('btn_start') click_by_pyautogui(START_UPLOAD_PNG) start = time.time() while True: li_ele = self.driver.find_elements_by_css_selector( '#image_list > li') els = [li.get_attribute('message') == '上传完毕' for li in li_ele] count_all = len(els) count_ok = sum(els) count_lack = count_all - count_ok if count_lack == 0: logger.info('上传完毕') break if time.time() - start > 60: logger.error('上传图片超时') js = 'return $(".tipsFont").text()' raise Pang5Exception(self.driver.execute_script(js)) logger.info( f'上传中, 共{count_all}个, {count_ok}个上传成功, {count_lack}个正在上传中。。。') time.sleep(4) if data[DATA_IS_CLOCK]: # 点击设置 # self.driver.find_element_by_css_selector('#open_release_time > span').click() publish_datetime = data[DATA_CLOCK_PUBLISH_DATETIME] if len(publish_datetime) == len('2010-10-10 04:00'): publish_datetime = publish_datetime + ':00' js = f'$("#input_release_time").val("{publish_datetime}")' logger.info(js) self.driver.execute_script(js) logger.info(f'设置定时时间为{publish_datetime}') # 暂时将下次更新时间设置为2天后. two_days_from_now = data[ DATA_NEXT_TIME] # or (datetime.now() + timedelta(days=2)).strftime('%Y-%m-%d') try: js = f'$("#input_update_time").val("{two_days_from_now}")' logger.info(js) self.driver.execute_script(js) logger.info(f'设置下次更新时间为{two_days_from_now}') except: logger.error('填写下次更新时间失败') logger.info('等待10s') time.sleep(10) logger.info('提交审核') self.driver.find_element_by_css_selector( '#main > div.borbox > div > div.tc > a').click() logger.info('发布成功') error_msg = self.driver.find_elements_by_css_selector( '#messageBox1 > table > tbody > tr > td') if len(error_msg) == 1: raise Pang5Exception(error_msg[0].text) update_status2OK()