def parse(self, an, cn, cp): # # xss注入参数 self.driver.find_element_by_xpath('//a[@class="normal fast_payBtn"]').click() # 点击快速充值 # self.driver.find_element_by_xpath('//input[@name="cn"]').send_keys(account_number) # 账号 # self.driver.find_element_by_xpath('//input[@name="cn2"]').send_keys(account_number) # 确认账号 # self.driver.find_element_by_xpath('//input[@name="cardNo"]').send_keys(card_number) # 卡号 # self.driver.find_element_by_xpath('//input[@name="cardPwd"]').send_keys(card_password) # 密码 self.driver.find_element_by_xpath('//input[@name="cn"]').send_keys(an) # 账号 self.driver.find_element_by_xpath('//input[@name="cn2"]').send_keys(an) # 确认账号 self.driver.find_element_by_xpath('//input[@name="cardNo"]').send_keys(cn) # 卡号 self.driver.find_element_by_xpath('//input[@name="cardPwd"]').send_keys(cp) # 密码 time.sleep(sleep_time()) self.driver.find_element_by_xpath('//*[@id="fast_pay_ul"]/li[4]/div').click() # 1 self.driver.find_element_by_xpath(self.choice_game).click() # 2 # 选择大区 try: self.driver.find_element_by_xpath('//*[@id="dlgame_select_rid"]/div').click() # 选择大区1 if self.choice_game == '//a[text()="幻想神域"]': # 31 self.driver.find_element_by_xpath('//a[text()="一区-启源大陆"]').click() # 选择大区2 elif self.choice_game == '//a[text()="海战世界"]': # 55 self.driver.find_element_by_xpath('//a[text()="中途岛(双线区)"]').click() # 选择大区2 elif self.choice_game == '//a[text()="星际战甲"]': # 42 self.driver.find_element_by_xpath('//*[@id="dlgame_region_id_box"]/a').click() # 选择大区2 except: print('你选的是前五个') time.sleep(sleep_time())
def run(self, an, cn, cp): time.sleep(sleep_time()) self.driver.get(self.url) # 打开网页 self.parse(an, cn, cp) data = self.fight() a = self.save(data) return a
def run(self, acc, pwd, num, cn, cp): time.sleep(sleep_time()) self.driver.get(self.url) # 打开网页 self.login(acc, pwd) data = self.parse(num, cn, cp) a = self.save(data) return a
def fight(self): # 验证码截取参数 self.driver.save_screenshot( '/www/wwwroot/www.stargame.com/media/sohu_sword_code.png') imgelement = self.driver.find_element_by_id('imageCodeId') # 定位验证码 location_dict = imgelement.location # 获取验证码x,y轴坐标 print('lo: ', location_dict) # lo_location = {'x': 562, 'y': 409} # {'x': 562, 'y': 409} lo_location = {'x': 1058, 'y': 409} # {'x': 1058, 'y': 409} 无界面 size_dict = imgelement.size # 获取验证码的长宽 print(size_dict) size = {'height': 26, 'width': 113} # {'height': 26, 'width': 113} rangle = (int(lo_location['x']), int(lo_location['y']), int(lo_location['x'] + size['width']), int(lo_location['y'] + size['height'])) # 写成我们需要截取的位置坐标 print(rangle) i = Image.open( '/www/wwwroot/www.stargame.com/media/sohu_sword_code.png') # 打开截图 frame4 = i.crop(rangle) # 使用Image的crop函数,从截图中再次截取我们需要的区域 rgb_im = frame4.convert('RGB') rgb_im.save('/www/wwwroot/www.stargame.com/media/sohu_sword_save.png' ) # 保存我们接下来的验证码图片 进行打码 # 打码 im = open('/www/wwwroot/www.stargame.com/media/sohu_sword_save.png', 'rb').read() data = self.chao_ji_ing.PostPic(im, 1005) code = data['pic_str'] print(data) if data['pic_str'] == '': statue = {'STATUE': 404, 'MSG': '系统超时'} self.chao_ji_ing.ReportError(code) print(statue) self.driver.find_element_by_id('annexcode').send_keys(code) # 验证码 time.sleep(sleep_time()) self.driver.save_screenshot( '/www/wwwroot/www.stargame.com/media/sohu_sword_yc_code.png' ) # 保存验证码后截图 self.driver.find_element_by_xpath( '//input[@value="下一步"]').click() # 下一步 u = self.driver.current_url # 判断是否验证成功 if u == 'http://chong.changyou.com/djbase/cardpwdUnLoginPay.do': st = self.driver.find_element_by_xpath( '//span[@class="import-txt"]').text statue = {'STATUE': 400, 'MSG': st} self.chao_ji_ing.ReportError(code) # print(statue) return statue else: print('充值成功') pass
def run(self, an, cn, cp, dis, ser): time.sleep(sleep_time()) self.driver.get(self.url) # 打开网页 self.click() self.input(an, cn, cp, dis, ser) aa = self.cut_img() self.save_img() self.fight_code(aa) a = self.save() return a
def fight(self): # 验证码截取参数 time.sleep(1.5) self.driver.save_screenshot('/www/wwwroot/www.stargame.com/media/test.png') imgelement = self.driver.find_element_by_xpath('//div[@class="geetest_item_wrap"]/img') # 定位验证码 location_dict = imgelement.location # 获取验证码x,y轴坐标 lo_location = {'x': 784, 'y': 332} size_dict = imgelement.size # 获取验证码的长宽 size = {'height': 411, 'width': 335} rangle = (int(lo_location['x']), int(lo_location['y']), int(lo_location['x'] + size['width']), int(lo_location['y'] + size['height'])) # 写成我们需要截取的位置坐标 i = Image.open("/www/wwwroot/www.stargame.com/media/test.png") # 打开截图 frame4 = i.crop(rangle) # 使用Image的crop函数,从截图中再次截取我们需要的区域 rgb_im = frame4.convert('RGB') rgb_im.save('/www/wwwroot/www.stargame.com/media/save.png') # 保存我们接下来的验证码图片 进行打码 # 打码 im = open('/www/wwwroot/www.stargame.com/media/save.png', 'rb').read() data = self.chao_ji_ing.PostPic(im, 9004) try: groups = data['pic_str'].split('|') print(data) # data_dict = {'err_no': 0, 'err_str': 'OK', 'pic_id': '6002001380949200001', 'pic_str': '90,247|155,147', 'md5': '1f8e1d4bef8b11484cb1f1f34299865b'} # data = json.dumps(data_dict) # d = json.loads(data) # groups = d['pic_str'].split('|') # 点击图片上的字段 locations = [[int(number) for number in group.split(',')] for group in groups] for ii in locations: print(ii) ActionChains(self.driver).move_to_element_with_offset(imgelement, ii[0] - 10, ii[1] - 40).click().perform() time.sleep(sleep_time()) self.driver.save_screenshot('/www/wwwroot/www.stargame.com/media/click.png') try: self.driver.find_element_by_xpath('//div[@class="geetest_commit_tip"]').click() except: statue = {'STATUE': 404, 'MSG': '点击确认出错'} self.chao_ji_ing.ReportError(data['pic_id']) return statue except: statue = {'STATUE': 404, 'MSG': '系统超时'} self.chao_ji_ing.ReportError(data['pic_id']) return statue time.sleep(2) # 确认订单信息 try: statue = {'STATUE': 200, 'MESSAGE': 'SUCCESS'} self.driver.find_element_by_id('confirm_order_submit').click() return statue except: statue = {'STATUE': 400, 'MESSAGE': '无法确认信息, 打码失败'} self.chao_ji_ing.ReportError(data['pic_id']) return statue
def run(self, acc, pwd, an, cn, cp): time.sleep(sleep_time()) self.driver.get(self.url) # 打开网页 self.click(acc, pwd) self.choice_fight() self.fight_bot() self.input(an, cn, cp) t = self.cut_img() self.save_img() a = self.fight_code(t) self.save() return a
def run(self, an, cn, cp): time.sleep(sleep_time()) self.driver.get(self.url) # 打开网页 self.parse(an, cn, cp) data = self.fight() a = self.save(data) return a # if __name__ == '__main__': # choice = '3' # R = SoHu(choice) # R.run()
rgb_im = frame4.convert('RGB') rgb_im.save('../media/sohu_sword_save.png') # 保存我们接下来的验证码图片 进行打码 # 打码 im = open('../media/sohu_sword_save.png', 'rb').read() data = chao_ji_ing.PostPic(im, 1005) code = data['pic_str'] print(data) if data['pic_str'] == '': statue = {'STATUE': 404, 'MSG': '系统超时'} chao_ji_ing.ReportError(code) print(statue) driver.find_element_by_id('annexcode').send_keys(code) # 验证码 time.sleep(sleep_time()) driver.save_screenshot('../media/sohu_sword_yc_code.png') # 保存验证码后截图 driver.find_element_by_xpath('//input[@value="下一步"]').click() # 下一步 u = driver.current_url # 判断是否验证成功 if u == 'http://chong.changyou.com/djbase/cardpwdUnLoginPay.do': st = driver.find_element_by_xpath('//span[@class="import-txt"]').text statue = {'STATUE': 400, 'MSG': st} chao_ji_ing.ReportError(code) print(statue) else: print('充值成功')
def choice_fight(self): time.sleep(1) try: try: st = self.driver.find_element_by_xpath( '//em[text()="依次"]').text print('这是点选验证码, 需要调用超级鹰', st) # 验证码截取参数 self.driver.save_screenshot( '/www/wwwroot/www.stargame.com/media/c_per.png') imgelement = self.driver.find_element_by_xpath( '//img[@class="wmPicCheck-checkImg"]') # 定位验证码 location_dict = imgelement.location # 获取验证码x,y轴坐标 print('lo: ', location_dict) # lo_location = location_dict # lo_location = {'x': 295, 'y': 235} # 显示 lo_location = {'x': 790, 'y': 330} # 隐藏 size_dict = imgelement.size # 获取验证码的长宽 print('sd: ', size_dict) # size = {'height': 340, 'width': 300} size = {'height': 400, 'width': 325} rangle = (int(lo_location['x']), int(lo_location['y']), int(lo_location['x'] + size['width']), int(lo_location['y'] + size['height']) ) # 写成我们需要截取的位置坐标 i = Image.open( '/www/wwwroot/www.stargame.com/media/c_per.png') # 打开截图 frame4 = i.crop(rangle) # 使用Image的crop函数,从截图中再次截取我们需要的区域 rgb_im = frame4.convert('RGB') rgb_im.save('/www/wwwroot/www.stargame.com/media/c_per_s.png') # 打码 im = open('../media/c_per_s.png', 'rb').read() data = self.chao_ji_ing.PostPic(im, 9004) try: groups = data['pic_str'].split('|') print(data) locations = [[int(number) for number in group.split(',')] for group in groups] for ii in locations: ActionChains(self.driver).move_to_element_with_offset( imgelement, ii[0] - 10, ii[1] - 40).click().perform() # ActionChains(driver).move_to_element_with_offset(imgelement, location[0], location[1]).click().perform() time.sleep(sleep_time()) try: self.driver.find_element_by_xpath( '//a[@class="wmPicCheck-check"]').click() except Exception as e: # print('验证码错误', e) self.chao_ji_ing.ReportError(data['pic_id']) statue = {'STATUE': 400, 'MSG': '验证码错误', 'DATA': e} return statue time.sleep(1.5) s = self.driver.find_element_by_xpath( '//a[@onclick="login(event);"]') self.driver.execute_script("arguments[0].click();", s) except Exception as e: statue = {'STATUE': 404, 'MSG': '系统超时', 'DATA': e} self.chao_ji_ing.ReportError(data['pic_id']) return statue except: st = self.driver.find_element_by_xpath( '//div[text()="向右拖动滑块完成拼图"]').text print('这是滑动验证码, 需要调用联众', st) # 截图1 try: display_element = self.driver.find_element_by_xpath( '//div[@class="m_sliderBarWrapper"]') ActionChains( self.driver).click_and_hold(display_element).perform() time.sleep(0.5) pic_url = self.driver.save_screenshot( '/www/wwwroot/www.stargame.com/media/perfect1.png') print("%s:截图成功!" % pic_url) imgelement = self.driver.find_element_by_xpath( '//div[@class="m_sliderImgShade"]') # 定位验证码 location_dict = imgelement.location # 获取验证码x,y轴坐标 print('lo: ', location_dict) # lo_location = {'x': 315, 'y': 363} # 显示 lo_location = location_dict # 隐藏 size_dict = imgelement.size # 获取验证码的长宽 print(size_dict) size = {'height': 120, 'width': 260} rangle = (int(lo_location['x']), int(lo_location['y']), int(lo_location['x'] + size['width']), int(lo_location['y'] + size['height']) ) # 写成我们需要截取的位置坐标 i = Image.open( '/www/wwwroot/www.stargame.com/media/perfect1.png' ) # 打开截图 frame4 = i.crop(rangle) # 使用Image的crop函数,从截图中再次截取我们需要的区域 rgb_im = frame4.convert('RGB') rgb_im.save( '/www/wwwroot/www.stargame.com/media/perfect_save1.png' ) try: # 打滑块 json_data = lianzhong( '/www/wwwroot/www.stargame.com/media/perfect_save1.png' ) json_data = json.loads(json_data) # json_data = {"data":{"val":"121,43","id":47833232020},"result":'true'} string = json_data['data']['val'] # 坐标 # id value_id = json_data['data']['id'] if '|' in string: a, b = string.split('|') a, c = a.split(',') b, d = b.split(',') x_offset = int(a) - int(b) offset = int(c) - int(d) # 返回值的第一个数和第三个数之差的绝对值就是要滑动的距离 x_offset = x_offset if x_offset > 0 else -x_offset offset = offset if offset > 0 else -offset print(offset, type(offset)) # 经过多次调试发现,如果两个坐标的y值之差大于7就会左偏 |c - d|的偏差 if offset >= 7: x_offset += offset print(x_offset, 'if') # return x_offset else: # 经过多次调试发现,打码平台有时候会返回没有'|'的字符串,而此时里面的第一个数就是距离 x_offset = string.split(',')[0] print(x_offset, 'else') # return int(x_offset) except Exception as e: print('滑块请求失败', e) statue = {'STATUE': 400, 'MSG': '滑块请求失败', 'DATA': e} lianzhong_wrong(value_id) return statue x = int(x_offset) try: # 滑动的动作链 ActionChains(self.driver).click_and_hold( display_element).perform() time.sleep(1) ActionChains(self.driver).move_by_offset( xoffset=x, yoffset=0).perform() time.sleep(2) # 此处一定要睡,如果不睡的话,可能还没拉到那个位置就直接进行下一步的动作了 ActionChains(self.driver).click().perform() except Exception as e: # print('滑动失败') statue = {'STATUE': 400, 'MSG': '滑动失败', 'DATA': e} lianzhong_wrong(value_id) return statue time.sleep(1.5) s = self.driver.find_element_by_xpath( '//a[@onclick="login(event);"]') self.driver.execute_script("arguments[0].click();", s) except Exception as e: # print('保存失败', e) statue = {'STATUE': 400, 'MSG': '保存失败', 'DATA': e} return statue except Exception as e: # print('选择打码失败', e) statue = {'STATUE': 400, 'MSG': '选择打码失败', 'DATA': e} return statue
def fight_bot(self): '''反机器人操作''' title = self.driver.title if title == '完美反机器人服务': print('被识别出来了?') try: # 点击验证 self.driver.find_element_by_xpath( '//*[@id="wanmeiCaptcha_0"]/div/p').click() except Exception as e: statue = {'STATUE': 400, 'MSG': '点击失败', 'DATA': e} print(statue, e) # 验证码截取参数 self.driver.save_screenshot( '/www/wwwroot/www.stargame.com/media/bot_fight.png') # 显示小滑块 display_element = self.driver.find_element_by_xpath( '//*[@id="ptCatptcha_0"]') self.driver.execute_script("arguments[0].style=arguments[1]", display_element, "display: block;") imgelement = self.driver.find_element_by_xpath( '//img[@class="wmPicCheck-checkImg"]') # 定位验证码 location_dict = imgelement.location # 获取验证码x,y轴坐标 print('lo: ', location_dict) # lo_location = location_dict # lo_location = {'x': 295, 'y': 235} lo_location = {'x': 790, 'y': 330} # 隐藏 size_dict = imgelement.size # 获取验证码的长宽 print('sd: ', size_dict) size = {'height': 400, 'width': 325} rangle = (int(lo_location['x']), int(lo_location['y']), int(lo_location['x'] + size['width']), int(lo_location['y'] + size['height'])) # 写成我们需要截取的位置坐标 i = Image.open('../media/bot_fight.png') # 打开截图 frame4 = i.crop(rangle) # 使用Image的crop函数,从截图中再次截取我们需要的区域 rgb_im = frame4.convert('RGB') rgb_im.save('/www/wwwroot/www.stargame.com/media/bot_fight.png') # 打码 im = open('/www/wwwroot/www.stargame.com/media/bot_fight.png', 'rb').read() data = self.chao_ji_ing.PostPic(im, 9004) try: groups = data['pic_str'].split('|') print(data) locations = [[int(number) for number in group.split(',')] for group in groups] for ii in locations: ActionChains(self.driver).move_to_element_with_offset( imgelement, ii[0] - 10, ii[1] - 40).click().perform() # ActionChains(driver).move_to_element_with_offset(imgelement, location[0], location[1]).click().perform() time.sleep(sleep_time()) try: self.driver.find_element_by_xpath( '//a[@class="wmPicCheck-check"]').click() except Exception as e: # print('验证码错误', e) self.chao_ji_ing.ReportError(data['pic_id']) statue = {'STATUE': 404, 'MSG': '验证码错误', 'DATA': e} return statue time.sleep(1.5) s = self.driver.find_element_by_xpath( '//a[@onclick="login(event);"]') self.driver.execute_script("arguments[0].click();", s) except Exception as e: statue = {'STATUE': 404, 'MSG': '系统超时', 'DATA': e} self.chao_ji_ing.ReportError(data['pic_id']) return statue self.driver.find_element_by_id('embed-submit').click() else: statue = {'STATUE': 200, 'MESSAGE': '呦呵, 通过了 -.= '} print(statue)
def fight(self): # 验证码截取参数 self.driver.save_screenshot('/www/wwwroot/www.stargame.com/media/sohu_code.png') imgelement = self.driver.find_element_by_id('checkcodeId') # 定位验证码 location_dict = imgelement.location # 获取验证码x,y轴坐标 print('lo: ', location_dict) if self.choice_game == '//a[text()="幻想神域"]': print('幻想神域') lo_location = {'x': 1128, 'y': 722} # lo_location = {'x': 616, 'y': 722} elif self.choice_game == '//a[text()="海战世界"]': print('海战世界') lo_location = {'x': 1128, 'y': 722} # lo_location = {'x': 616, 'y': 722} elif self.choice_game == '//a[text()="星际战甲"]': print('星际战甲') lo_location = {'x': 1128, 'y': 722} # lo_location = {'x': 616, 'y': 722} else: print('前五个') lo_location = {'x': 1128, 'y': 680} # lo_location = {'x': 618, 'y': 679} size_dict = imgelement.size # 获取验证码的长宽 print(size_dict) size = {'height': 33, 'width': 91} rangle = (int(lo_location['x']), int(lo_location['y']), int(lo_location['x'] + size['width']), int(lo_location['y'] + size['height'])) # 写成我们需要截取的位置坐标 print(rangle) i = Image.open("/www/wwwroot/www.stargame.com/media/sohu_code.png") # 打开截图 frame4 = i.crop(rangle) # 使用Image的crop函数,从截图中再次截取我们需要的区域 rgb_im = frame4.convert('RGB') rgb_im.save('/www/wwwroot/www.stargame.com/media/sohu_save.png') # 保存我们接下来的验证码图片 进行打码 # 打码 im = open('/www/wwwroot/www.stargame.com/media/sohu_save.png', 'rb').read() data = self.chao_ji_ing.PostPic(im, 1005) print(data) if data['pic_str'] == '': statue = {'STATUE': 404, 'MSG': '系统超时'} self.chao_ji_ing.ReportError(data['pic_id']) # print(statue) return statue # data_dict = {'err_no': 0, 'err_str': 'OK', 'pic_id': '9122415085089600039', 'pic_str': 'RNCZM', 'md5': '22fda2e7d516a448c271486dc35f32f0'} # code = data_dict['pic_str'] # if data_dict['pic_str'] == '': # statue = {'STATUE': 404, 'MSG': '系统超时'} # chao_ji_ing.ReportError(data['pic_id']) code = data['pic_str'] self.driver.find_element_by_id('annexcode').send_keys(code) # 验证码 time.sleep(sleep_time()) self.driver.save_screenshot('/www/wwwroot/www.stargame.com/media/sohu_yc_code.png') # 保存验证码后截图 self.driver.find_element_by_xpath('//a[text()="充值"]').click() # 立即充值 st = self.driver.find_element_by_xpath('//p[@id="error"]').text if st == '呦!您输入的验证码不正确呀': statue = {'STATUE': 400, 'MESSAGE': '验证码错误, 打码失败'} self.chao_ji_ing.ReportError(data['pic_id']) # print(statue) return statue else: statue = {'STATUE': 200, 'MESSAGE': 'SUCCESS'} # 确认订单信息 # 获取充值结果 # print(statue) return statue