Ejemplo n.º 1
0
 def change_pwd(self, brower, wait):
     brower.find_element_by_xpath('//a[text()="修改密码"]').click()
     wait.until(
         EC.presence_of_element_located(
             (By.XPATH,
              '//input[@name="oldpwd"]'))).send_keys(self.password)
     if self.password == 'salesmind1800':
         newpassword = '******'
     else:
         newpassword = '******'
     wait.until(
         EC.presence_of_element_located(
             (By.XPATH,
              '//input[@name="user_pwd"]'))).send_keys(newpassword)
     wait.until(
         EC.presence_of_element_located(
             (By.XPATH, '//input[@data-nick="ok_new_password"]'
              ))).send_keys(newpassword)
     while True:
         imgelement = wait.until(
             EC.presence_of_element_located(
                 (By.XPATH, '//img[@data-selector="ver-code"]')))
         location = imgelement.location  # 获取滑条x,y轴坐标
         if location['x'] == 0:
             return
         brower.save_screenshot(BASE_DIR + '/' +
                                'liepin_.png')  # 截取当前网页,该网页有我们需要的验证码
         size = imgelement.size  # 获取滑条的长宽
         rangle = (int(location['x']), int(location['y']),
                   int(location['x'] + size['width']),
                   int(location['y'] + size['height']))  # 写成我们需要截取的位置坐标
         i = Image.open(BASE_DIR + '/' + "liepin_.png")  # 打开截图
         frame4 = i.crop(rangle)  # 使用Image的crop函数,从截图中再次截取我们需要的区域
         frame4.save(BASE_DIR + '/' + 'liepinyzm.png')
         chaojiying = Chaojiying_Client('jackie1102', 'salesmind1800',
                                        '1902')
         im = open(BASE_DIR + '/' + 'liepinyzm.png', 'rb').read()
         res = chaojiying.PostPic(im, 1902)
         pic_str = res['pic_str']
         os.remove(BASE_DIR + '/' + "liepin_.png")
         os.remove(BASE_DIR + '/' + "liepinyzm.png")
         inpt = brower.find_element_by_xpath('//input[@name="verifycode"]')
         inpt.clear()
         time.sleep(1)
         inpt.send_keys(pic_str)
         time.sleep(1)
         brower.find_element_by_xpath('//button[@type="submit"]').click()
         time.sleep(1)
         try:
             button = brower.find_element_by_xpath('//a[@data-name="ok"]')
             if button:
                 chaojiying.ReportError(res['pic_id'])
                 button.click()
                 time.sleep(2)
                 imgelement.click()
         except:
             break
     time.sleep(1)
     return newpassword
Ejemplo n.º 2
0
 def login(self):
     self.driver.get('https://ehire.51job.com/')
     js1 = "document.getElementsByClassName('headerBanner')[0].style.display='none'"
     js2 = "document.getElementsByClassName('topHeader')[0].style.display='none'"
     self.driver.execute_script(js1)
     self.driver.execute_script(js2)
     self.wait.until(EC.presence_of_element_located((By.XPATH, '//*[@id="txtMemberNameCN"]'))).send_keys(
         self.vipname)
     self.wait.until(EC.presence_of_element_located((By.XPATH, '//*[@id="txtUserNameCN"]'))).send_keys(self.username)
     self.wait.until(EC.presence_of_element_located((By.XPATH, '//*[@id="txtPasswordCN"]'))).send_keys(self.password)
     self.wait.until(EC.presence_of_element_located((By.XPATH, '//*[@id="btnBeginValidate"]'))).click()
     while True:
         time.sleep(1)
         imgelement = self.driver.find_element_by_xpath('//*[@id="divValidateHtml"]/div')  # 定位验证码
         self.driver.save_screenshot('aa.png')  # 截取当前网页,该网页有我们需要的验证码
         location = imgelement.location  # 获取验证码x,y轴坐标
         print(location)
         if location['x'] == 0:
             return
         size = imgelement.size  # 获取验证码的长宽
         print(size['width'])
         rangle = (int(location['x']), int(location['y']), int(location['x'] + size['width']),
                   int(location['y'] + size['height']))  # 写成我们需要截取的位置坐标
         i = Image.open("aa.png")  # 打开截图
         frame4 = i.crop(rangle)  # 使用Image的crop函数,从截图中再次截取我们需要的区域
         frame4.save('frame4.png')
         chaojiying = Chaojiying_Client('jackie1102', 'salesmind1800', '9004')
         im = open('frame4.png', 'rb').read()
         while True:
             try:
                 res = chaojiying.PostPic(im, 9004)
             except Exception as E:
                 print(E)
                 time.sleep(2)
                 continue
             break
         content = res['pic_str'].split('|')
         loc_list = []
         for i in content:
             loc = i.split(',')
             loc_list.append(loc)
         action = ActionChains(self.driver)
         for loca in loc_list:
             action.move_to_element_with_offset(imgelement, int(loca[0]), int(loca[1])).click()
             action.pause(1)
         action.perform()
         time.sleep(1)
         self.wait.until(EC.presence_of_element_located((By.LINK_TEXT, '验 证'))).click()
         time.sleep(1)
         success = self.driver.find_element_by_xpath('//*[@id="btnEndValidate"]').text
         if success == '验证通过':
             break
         else:
             chaojiying.ReportError(res['pic_id'])
             time.sleep(3)
     self.driver.find_element_by_xpath('//*[@id="Login_btnLoginCN"]').click()
Ejemplo n.º 3
0
 def yzm1(self):
     while True:
         # 定位滑条
         imgelement1 = self.wait.until(
             EC.presence_of_element_located(
                 (By.XPATH, '//*[@id="nc_1__scale_text"]')))
         self.driver.save_screenshot('qichacha.png')  # 截取当前网页,该网页有我们需要的验证码
         location = imgelement1.location  # 获取滑条x,y轴坐标
         size1 = imgelement1.size  # 获取滑条的长宽
         # 定位验证码
         try:
             imgelement2 = self.driver.find_element_by_xpath(
                 '//*[@id="nc_1_clickCaptcha"]')
         except:
             return
         size2 = imgelement2.size  # 获取验证码的长宽
         rangle = (int(location['x']), int(location['y']),
                   int(location['x'] + size1['width']),
                   int(location['y'] + size1['height'] + size2['height'])
                   )  # 写成我们需要截取的位置坐标
         i = Image.open("qichacha.png")  # 打开截图
         frame4 = i.crop(rangle)  # 使用Image的crop函数,从截图中再次截取我们需要的区域
         frame4.save('qichachayzm.png')
         chaojiying = Chaojiying_Client('jackie1102', 'salesmind1800',
                                        '9101')
         im = open('qichachayzm.png', 'rb').read()
         res = chaojiying.PostPic(im, 9101)
         content = res['pic_str']
         loca = content.split(',')
         action = ActionChains(self.driver)
         action.move_to_element_with_offset(imgelement1, int(loca[0]),
                                            int(loca[1]))
         action.click()
         action.perform()
         time.sleep(1)
         try:
             text = self.driver.find_element_by_xpath(
                 '//*[@id="nc_1__scale_text"]/span/b').text
             if text == '验证通过':
                 break
         except Exception:
             # print('验证失败')
             chaojiying.ReportError(res['pic_id'])
         time.sleep(1)
     try:
         self.driver.find_element_by_xpath('//*[@id="verify"]').click()
         time.sleep(1)
     except:
         pass
Ejemplo n.º 4
0
 def yzm2(self):
     while True:
         imgelement = self.wait.until(
             EC.presence_of_element_located(
                 (By.XPATH, '//*[@id="nc_1__imgCaptcha_img"]/img')))
         location = imgelement.location  # 获取滑条x,y轴坐标
         if location['x'] == 0:
             return
         self.driver.save_screenshot('qichacha.png')  # 截取当前网页,该网页有我们需要的验证码
         size = imgelement.size  # 获取滑条的长宽
         rangle = (int(location['x']), int(location['y']),
                   int(location['x'] + size['width']),
                   int(location['y'] + size['height']))  # 写成我们需要截取的位置坐标
         i = Image.open("qichacha.png")  # 打开截图
         frame4 = i.crop(rangle)  # 使用Image的crop函数,从截图中再次截取我们需要的区域
         frame4.save('qichachayzm.png')
         chaojiying = Chaojiying_Client('jackie1102', 'salesmind1800',
                                        '1902')
         im = open('qichachayzm.png', 'rb').read()
         res = chaojiying.PostPic(im, 1902)
         pic_str = res['pic_str']
         os.remove("qichacha.png")
         os.remove("qichachayzm.png")
         inpt = self.driver.find_element_by_xpath(
             '//*[@id="nc_1_captcha_input"]')
         inpt.clear()
         time.sleep(1)
         inpt.send_keys(pic_str)
         time.sleep(1)
         self.driver.find_element_by_xpath(
             '//*[@id="nc_1_scale_submit"]/span').click()
         time.sleep(1)
         try:
             txt = self.driver.find_element_by_xpath(
                 '//*[@id="nc_1__captcha_img_text"]/span').text
             if txt:
                 chaojiying.ReportError(res['pic_id'])
                 time.sleep(2)
         except:
             break
     time.sleep(1)
     try:
         self.driver.find_element_by_xpath('//*[@id="verify"]').click()
         time.sleep(1)
     except:
         pass
Ejemplo n.º 5
0
 def check_yzm(self):
     """
      验证码处理:
     1·捕获验证码,对当前页面进行截屏
     2·定位验证码图片位置,并从截屏中提取
     3·调用打码平台,破解验证码,返回验证码参数
     4·对验证码参数进一步处理,并模拟人工操作破解验证码
     5·验证是否破解成功,否则发送验证失败api
     :return:
     """
     while True:
         try:
             imgelement = self.driver.find_element_by_xpath('//*[@id="divValidateHtml"]/div')  # 定位验证码
             self.driver.save_screenshot('aa.png')  # 截取当前网页,该网页有我们需要的验证码
             location = imgelement.location  # 获取验证码x,y轴坐标
             if location['x'] == 0:
                 return
             size = imgelement.size  # 获取验证码的长宽
             rangle = (int(location['x']), int(location['y']), int(location['x'] + size['width']),
                       int(location['y'] + size['height']))  # 写成我们需要截取的位置坐标
             i = Image.open("aa.png")  # 打开截图
             frame4 = i.crop(rangle)  # 使用Image的crop函数,从截图中再次截取我们需要的区域
             frame4.save('frame4.png')
             chaojiying = Chaojiying_Client('jackie1102', 'salesmind1800', '9004')
             im = open('frame4.png', 'rb').read()
             while True:
                 try:
                     res = chaojiying.PostPic(im, 9004)
                 except Exception as E:
                     print(E)
                     time.sleep(2)
                     continue
                 break
             content = res['pic_str'].split('|')
             print(res)
             loc_list = []
             for i in content:
                 loc = i.split(',')
                 loc_list.append(loc)
             action = ActionChains(self.driver)
             for loca in loc_list:
                 action.move_to_element_with_offset(imgelement, int(loca[0]), int(loca[1])).click()
                 action.pause(1)
             action.perform()
             time.sleep(1)
             self.wait.until(EC.presence_of_element_located((By.LINK_TEXT, '验 证'))).click()
             time.sleep(1)
             self.driver.refresh()
             imgelement = self.driver.find_element_by_xpath('//*[@id="divValidateHtml"]/div')  # 定位验证码
             print(imgelement, '111111')
             self.driver.save_screenshot('d://aa.png')  # 截取当前网页,该网页有我们需要的验证码
             location = imgelement.location  # 获取验证码x,y轴坐标
             print(location)
             if location['x'] == 0:
                 print('验证成功')
             else:
                 print('验证失败')
                 chaojiying.ReportError(res['pic_id'])
             time.sleep(3)
         except:
             print('没有出现验证码')
             break
Ejemplo n.º 6
0
 def yzm(self):
     """
     浏览器模拟登陆处理验证码
     :return:
     """
     driver = self.login()
     driver.get('https://antirobot.tianyancha.com/captcha/verify?')
     time.sleep(2)
     while True:
         try:
             imgelement = self.driver.find_element_by_xpath(
                 '//div[@class="new-box94"]')  # 定位验证码
             self.driver.save_screenshot(
                 'tianyancha.png')  # 截取当前网页,该网页有我们需要的验证码
             location = imgelement.location  # 获取验证码x,y轴坐标
             if location['x'] == 0:
                 return
             size = imgelement.size  # 获取验证码的长宽
             # print(size['width'])
             rangle = (int(location['x']), int(location['y']),
                       int(location['x'] + size['width']),
                       int(location['y'] + size['height']))  # 写成我们需要截取的位置坐标
             i = Image.open("tianyancha.png")  # 打开截图
             frame4 = i.crop(rangle)  # 使用Image的crop函数,从截图中再次截取我们需要的区域
             frame4.save('frame_tyc.png')
             chaojiying = Chaojiying_Client('jackie1102', 'salesmind1800',
                                            '9004')
             im = open('frame_tyc.png', 'rb').read()
             while True:
                 try:
                     res = chaojiying.PostPic(im, 9004)
                 except Exception as E:
                     # print(E)
                     continue
                 break
             content = res['pic_str'].split('|')
             loc_list = []
             for i in content:
                 loc = i.split(',')
                 loc_list.append(loc)
             action = ActionChains(self.driver)
             for loca in loc_list:
                 action.move_to_element_with_offset(imgelement,
                                                    int(loca[0]),
                                                    int(loca[1])).click()
             action.perform()
             time.sleep(1)
             self.wait.until(
                 EC.presence_of_element_located(
                     (By.XPATH, '//*[@id="submitie"]'))).click()
             time.sleep(1)
             self.driver.refresh()
             imgelement = self.driver.find_element_by_xpath(
                 '//div[@class="new-box94"]')  # 定位验证码
             location = imgelement.location  # 获取验证码x,y轴坐标
             if location['x'] == 0:
                 # print('验证成功')
                 break
             else:
                 # print('验证失败')
                 chaojiying.ReportError(res['pic_id'])
         except Exception:
             break
     driver.quit()
Ejemplo n.º 7
0
 def login(self):
     """
     登录网站
     :return:
     """
     chrome_options = Options()
     chrome_options.add_argument('window-size=1920x1500')  # 指定浏览器分辨率
     chrome_options.add_argument('--disable-gpu')  # 谷歌文档提到需要加上这个属性来规避bug
     chrome_options.add_argument('--hide-scrollbars')  # 隐藏滚动条, 应对一些特殊页面
     chrome_options.add_argument(
         '--headless')  # 浏览器不提供可视化页面. linux下如果系统不支持可视化不加这条会启动失败
     # driver = webdriver.Chrome()
     driver = webdriver.Chrome(chrome_options=chrome_options)
     driver.maximize_window()
     wait = WebDriverWait(driver, 5)
     driver.get('https://ehire.51job.com/')
     time.sleep(1)
     while True:
         wait.until(
             EC.presence_of_element_located(
                 (By.XPATH,
                  '//*[@id="txtMemberNameCN"]'))).send_keys(self.vipname)
         wait.until(
             EC.presence_of_element_located(
                 (By.XPATH,
                  '//*[@id="txtUserNameCN"]'))).send_keys(self.username)
         wait.until(
             EC.presence_of_element_located(
                 (By.XPATH,
                  '//*[@id="txtPasswordCN"]'))).send_keys(self.password)
         wait.until(
             EC.presence_of_element_located(
                 (By.XPATH, '//*[@id="btnBeginValidate"]'))).click()
         time.sleep(1)
         while True:
             imgelement = driver.find_element_by_xpath(
                 '//*[@id="divValidateHtml"]/div')  # 定位验证码
             location = imgelement.location  # 获取验证码x,y轴坐标
             if location['x'] == 0:
                 return
             driver.save_screenshot(BASE_DIR + '/' + self.table_name +
                                    '_job.png')  # 截取当前网页,该网页有我们需要的验证码
             size = imgelement.size  # 获取验证码的长宽
             rangle = (int(location['x']), int(location['y']),
                       int(location['x'] + size['width']),
                       int(location['y'] + size['height']))  # 写成我们需要截取的位置坐标
             i = Image.open(BASE_DIR + '/' + self.table_name +
                            '_job.png')  # 打开截图
             frame = i.crop(rangle)  # 使用Image的crop函数,从截图中再次截取我们需要的区域
             frame.save(BASE_DIR + '/' + self.table_name + 'frame.png')
             chaojiying = Chaojiying_Client('jackie1102', 'salesmind1800',
                                            '9004')
             im = open(BASE_DIR + '/' + self.table_name + 'frame.png',
                       'rb').read()
             while True:
                 try:
                     res = chaojiying.PostPic(im, 9004)
                 except Exception as E:
                     time.sleep(2)
                     continue
                 break
             os.remove(BASE_DIR + '/' + self.table_name + '_job.png')
             os.remove(BASE_DIR + '/' + self.table_name + 'frame.png')
             content = res['pic_str'].split('|')
             loc_list = []
             for i in content:
                 loc = i.split(',')
                 loc_list.append(loc)
             action = ActionChains(driver)
             for loca in loc_list:
                 action.move_to_element_with_offset(imgelement,
                                                    int(loca[0]),
                                                    int(loca[1])).click()
             action.perform()
             time.sleep(1)
             wait.until(
                 EC.presence_of_element_located(
                     (By.LINK_TEXT, '验 证'))).click()
             time.sleep(1)
             success = driver.find_element_by_xpath(
                 '//*[@id="btnEndValidate"]').text
             if success == '验证通过':
                 break
             else:
                 chaojiying.ReportError(res['pic_id'])
                 time.sleep(3)
         driver.find_element_by_xpath('//*[@id="Login_btnLoginCN"]').click()
         try:
             wait.until(
                 EC.presence_of_element_located(
                     (By.XPATH, '//a[text()="强制下线"]'))).click()
             time.sleep(2)
             url = driver.current_url
             if 'Navigate.aspx?' in url:
                 break
             else:
                 continue
         except:
             break
     time.sleep(5)
     cookie = [
         item["name"] + "=" + item["value"]
         for item in driver.get_cookies()
     ]
     cookiestr = '; '.join(item for item in cookie)
     print(cookiestr)
     driver.quit()
     return cookiestr
Ejemplo n.º 8
0
 def login(self):
     """
     登录网站
     :return:
     """
     options = webdriver.FirefoxOptions()
     options.add_argument('-headless')
     options.add_argument('--disable-gpu')
     driver = webdriver.Firefox(firefox_options=options)
     # driver = webdriver.Firefox()
     driver.maximize_window()
     wait = WebDriverWait(driver, 5)
     driver.get('https://passport.zhaopin.com/org/login')
     time.sleep(2)
     wait.until(
         EC.presence_of_element_located(
             (By.XPATH, '//*[@id="loginName"]'))).send_keys(self.username)
     time.sleep(2)
     wait.until(
         EC.presence_of_element_located(
             (By.XPATH, '//*[@id="password"]'))).send_keys(self.password)
     time.sleep(2)
     while True:
         wait.until(
             EC.presence_of_element_located(
                 (By.XPATH, '//*[@id="loginbutton"]'))).click()
         time.sleep(2)
         imgelement = wait.until(
             EC.presence_of_element_located(
                 (By.XPATH, '//div[@class="geetest_head"]')))  # 定位验证码
         location1 = imgelement.location  # 获取验证码x,y轴坐标
         if location1['x'] == 0:
             continue
         else:
             break
     while True:
         imgelement1 = wait.until(
             EC.presence_of_element_located(
                 (By.XPATH, '//div[@class="geetest_head"]')))  # 定位验证码
         imgelement2 = wait.until(
             EC.presence_of_element_located(
                 (By.XPATH, '//div[@class="geetest_table_box"]')))  # 定位验证码
         location1 = imgelement1.location  # 获取验证码x,y轴坐标
         if location1['x'] == 0:
             break
         driver.save_screenshot('aa.png')  # 截取当前网页,该网页有我们需要的验证码
         size1 = imgelement1.size  # 获取验证码的长宽
         size2 = imgelement2.size  # 获取验证码的长宽
         rangle = (int(location1['x']), int(location1['y']),
                   int(location1['x'] + size1['width']),
                   int(location1['y'] + size1['height'] + size2['height'])
                   )  # 写成我们需要截取的位置坐标
         i = Image.open("aa.png")  # 打开截图
         frame4 = i.crop(rangle)  # 使用Image的crop函数,从截图中再次截取我们需要的区域
         frame4.save('frame4.png')
         chaojiying = Chaojiying_Client('jackie1102', 'salesmind1800',
                                        '9004')
         im = open('frame4.png', 'rb').read()
         res = chaojiying.PostPic(im, 9004)
         content = res['pic_str'].split('|')
         print(res)
         loc_list = []
         for i in content:
             loc = i.split(',')
             loc_list.append(loc)
         action = ActionChains(driver)
         loc1 = loc_list[0]
         try:
             x = int(loc1[0])
         except Exception as E:
             print(E)
             chaojiying.ReportError(res['pic_id'])
             continue
         for loca in loc_list:
             action.move_to_element_with_offset(imgelement1, int(loca[0]),
                                                int(loca[1])).click()
             action.pause(random.uniform(1, 2))
         action.perform()
         time.sleep(1)
         wait.until(
             EC.presence_of_element_located(
                 (By.XPATH, '//a[@class="geetest_commit"]'))).click()
         time.sleep(2)
         try:
             imgelement = wait.until(
                 EC.presence_of_element_located(
                     (By.XPATH, '//div[@class="geetest_widget"]')))
             location = imgelement.location
             if location['x'] == 0:
                 break
             else:
                 chaojiying.ReportError(res['pic_id'])
                 time.sleep(1)
                 continue
         except:
             break
     try:
         input_phone = driver.find_element_by_xpath('//*[@id="vmobile"]')
         pc = PhoneCode()
         phone = pc.get_phone()
         input_phone.send_keys(phone)
         driver.find_element_by_xpath(
             '//a[@class="verify_code_btn"]').click()
         while True:
             imgelement1 = wait.until(
                 EC.presence_of_element_located(
                     (By.XPATH, '//div[@class="geetest_head"]')))  # 定位验证码
             imgelement2 = wait.until(
                 EC.presence_of_element_located(
                     (By.XPATH,
                      '//div[@class="geetest_table_box"]')))  # 定位验证码
             driver.save_screenshot('aa.png')  # 截取当前网页,该网页有我们需要的验证码
             location1 = imgelement1.location  # 获取验证码x,y轴坐标
             print(location1)
             if location1['x'] == 0:
                 break
             size1 = imgelement1.size  # 获取验证码的长宽
             size2 = imgelement2.size  # 获取验证码的长宽
             print(size1['width'])
             rangle = (int(location1['x']), int(location1['y']),
                       int(location1['x'] + size1['width']),
                       int(location1['y'] + size1['height'] +
                           size2['height']))  # 写成我们需要截取的位置坐标
             i = Image.open("aa.png")  # 打开截图
             frame4 = i.crop(rangle)  # 使用Image的crop函数,从截图中再次截取我们需要的区域
             frame4.save('frame4.png')
             chaojiying = Chaojiying_Client('jackie1102', 'salesmind1800',
                                            '9004')
             im = open('frame4.png', 'rb').read()
             res = chaojiying.PostPic(im, 9004)
             content = res['pic_str'].split('|')
             print(res)
             loc_list = []
             for i in content:
                 loc = i.split(',')
                 loc_list.append(loc)
             action = ActionChains(driver)
             loc1 = loc_list[0]
             try:
                 x = int(loc1[0])
             except Exception as E:
                 print(E)
                 chaojiying.ReportError(res['pic_id'])
                 continue
             for loca in loc_list:
                 action.move_to_element_with_offset(imgelement1,
                                                    int(loca[0]),
                                                    int(loca[1])).click()
                 action.pause(random.uniform(1, 2))
             action.perform()
             time.sleep(1)
             wait.until(
                 EC.presence_of_element_located(
                     (By.XPATH, '//a[@class="geetest_commit"]'))).click()
             time.sleep(2)
             try:
                 imgelement = wait.until(
                     EC.presence_of_element_located(
                         (By.XPATH, '//div[@class="geetest_widget"]')))
                 location = imgelement.location
                 if location['x'] == 0:
                     break
                 else:
                     chaojiying.ReportError(res['pic_id'])
                     time.sleep(1)
                     continue
             except:
                 break
         code = pc.get_code(phone)
         input_code = driver.find_element_by_xpath('//*[@id="verifyCode"]')
         input_code.send_keys(code)
         driver.find_element_by_xpath('//*[@id="confirm_btn"]').click()
     except:
         pass
     time.sleep(5)
     cookie = [
         item["name"] + "=" + item["value"]
         for item in driver.get_cookies()
     ]
     cookiestr = '; '.join(item for item in cookie)
     print(cookiestr)
     driver.quit()
     return cookiestr