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 login_mobile(self) -> bool: # 访问移动端 self.driver.get('http://m.ac.qq.com/') # 点击右上角菜单 self.driver.find_element_by_css_selector( 'body > header > a.btn-top.menu').click() # 点击我的地盘 self.driver.find_element_by_css_selector( 'body > div.nav-menu-box.show > div.nav-menu > a').click() if get_current_url() == 'http://m.ac.qq.com/home/index': logger.info('已经登录') return True # 输入用户名 self.driver.find_element_by_css_selector('#u').send_keys( data[DATA_USERNAME]) self.driver.find_element_by_css_selector('#p').send_keys( data[DATA_PASSWORD]) time.sleep(1) self.driver.find_element_by_css_selector('#go').click() time.sleep(5) ok = get_current_url() == 'http://m.ac.qq.com/home/index' 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=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 login_mobile_qq(self): self.driver.get(LOGIN_MOBILE_URL) # 点击qq self.driver.find_element_by_css_selector( '#coagent > a.coagent.coagent-qq').click() time.sleep(1) self.driver.switch_to_frame( self.driver.find_element_by_id("ptlogin_iframe")) self.driver.find_element_by_id('switcher_plogin').click() time.sleep(3) u = self.driver.find_element_by_id('u') u.clear() u.send_keys(data[DATA_USERNAME]) p = self.driver.find_element_by_id('p') p.clear() p.send_keys(data[DATA_PASSWORD]) self.driver.find_element_by_id('login_button').click() time.sleep(3) ok = get_current_url() == AUTH_MOBILE_OK_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 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 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_mobile(self) -> bool: self.driver.get(LOGIN_MOBILE_URL) self.driver.find_element_by_css_selector( '#wrapper > div > div:nth-child(2) > input').send_keys( data[DATA_USERNAME]) self.driver.find_element_by_css_selector( '#wrapper > div > div:nth-child(3) > input:nth-child(1)' ).send_keys(data[DATA_PASSWORD]) time.sleep(1) self.driver.find_element_by_css_selector( '#wrapper > div > a.green-btn.login-btn').click() time.sleep(2) ok = get_current_url() == AUTH_MOBILE_OK_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 login_mobile_weibo(self): self.driver.get(LOGIN_MOBILE_URL) # 点击微博 self.driver.find_element_by_css_selector( 'a.coagent-weibo:nth-child(2)').click() time.sleep(1) self.driver.find_element_by_css_selector('#userId').send_keys( data[DATA_USERNAME]) self.driver.find_element_by_css_selector('#passwd').send_keys( data[DATA_PASSWORD]) time.sleep(1) self.driver.find_element_by_css_selector('.WB_btn_login').click() time.sleep(3) ok = get_current_url() == AUTH_MOBILE_OK_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 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 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 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(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)