class WorldCar(object): '''创世战车充值入口''' def __init__(self): # 驱动参数 self.chao_ji_ing = Chaojiying_Client( 'nap2017', 'qweasdzxc', '909537') # 用户中心>>软件ID 生成一个替换 96001 self.options = webdriver.ChromeOptions() self.options.add_argument('--user-agent={}'.format(ua_pond)) self.options.add_argument('window-size=1920x1080') # 指定浏览器分辨率 self.options.add_argument('--headless') # 无界面模式 self.options.add_argument('--disable-gpu') # 隐藏gpu界面 self.options.add_argument('--proxy-server=http://{}'.format( ip_port())) # ip 代理 self.driver = webdriver.Chrome('/usr/local/bin/chromedriver', chrome_options=self.options) # 基本参数 self.url = 'https://pay.wanmei.com/new/proxypay.do?op=prepay&gametype=200013' # def parse(self): def parse(self, an, cn, cp): try: self.driver.find_element_by_xpath( '//em[text()="完美一卡通"]').click() # 选择完美一卡通 time.sleep(0.5) num = perfect_number('账号') # self.driver.find_element_by_name('username').send_keys(num) # 账号 self.driver.find_element_by_name('username').send_keys(an) # 账号 # self.driver.find_element_by_name('username2').send_keys(num) # 再次账号 self.driver.find_element_by_name('username2').send_keys(an) # 再次账号 # self.driver.find_element_by_name('cardnumber').send_keys(perfect_topup('卡号')) # 卡号 self.driver.find_element_by_name('cardnumber').send_keys(cn) # 卡号 self.driver.find_element_by_name('cardpasswd').send_keys(cp) # 密码 # self.driver.find_element_by_name('cardpasswd').send_keys(perfect_topup('卡密')) # 密码 except Exception as e: statue = {'STATUE': 400, 'MESSAGE': '账号密码无法输入'} print(statue) # 选择大区 self.driver.find_element_by_class_name('select').click() try: element = self.driver.find_element_by_xpath( '/html/body/div[7]/dl/dd/div/a') self.driver.execute_script("arguments[0].click();", element) print('-----服务器已选择-----') except Exception as e: print(e) def fight(self): # 验证码截取参数 self.driver.save_screenshot( '/www/wwwroot/www.stargame.com/media/car_code.png') imgelement = self.driver.find_element_by_id('randimg') # 定位验证码 location_dict = imgelement.location # 获取验证码x,y轴坐标 print('lo: ', location_dict) # lo_location = {'x': 516, 'y': 567} # 显示 lo_location = {'x': 975, 'y': 567} # 隐式 size_dict = imgelement.size # 获取验证码的长宽 print('hw: ', size_dict) size = {'height': 28, 'width': 80} rangle = (int(lo_location['x']), int(lo_location['y']), int(lo_location['x'] + size['width']), int(lo_location['y'] + size['height'])) # 写成我们需要截取的位置坐标 print('four: ', rangle) i = Image.open( "/www/wwwroot/www.stargame.com/media/car_code.png") # 打开截图 frame4 = i.crop(rangle) # 使用Image的crop函数,从截图中再次截取我们需要的区域 rgb_im = frame4.convert('RGB') rgb_im.save('/www/wwwroot/www.stargame.com/media/car_save.png' ) # 保存我们接下来的验证码图片 进行打码 # 打码 im = open('/www/wwwroot/www.stargame.com/media/car_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 code = data['pic_str'] # code = 'pgov' try: self.driver.find_element_by_id('rand').send_keys(code) # 验证码输入 except Exception as e: statue = {'STATUE': 400, 'MESSAGE': '验证码输入有误'} self.chao_ji_ing.ReportError(data['pic_id']) # print(statue) return statue # 提交 time.sleep(0.5) try: self.driver.find_element_by_class_name('btn01').click() except Exception as e: statue = {'STATUE': 400, 'MESSAGE': '点击失败'} self.chao_ji_ing.ReportError(data['pic_id']) # print(statue) return statue time.sleep(1) self.driver.find_element_by_xpath( '//*[@id="div1"]/div/center/a[1]').click() # 二次确认充值 if self.driver.find_element_by_xpath( '//div[@class="other_error"]').text == '验证码错误,请您重新输入': statue = {'STATUE': 400, 'MESSAGE': '验证失败'} self.chao_ji_ing.ReportError(data['pic_id']) # print(statue) return statue else: statue = {'STATUE': 200, 'MESSAGE': '充值成功'} # self.chao_ji_ing.ReportError(data['pic_id']) # print(statue) return statue def save(self, statue): # 获取充值结果 print(statue) print(self.driver.title) time.sleep(5) self.driver.quit() return statue 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
size = {'height': 28, 'width': 80} rangle = (int(lo_location['x']), int(lo_location['y']), int(lo_location['x'] + size['width']), int(lo_location['y'] + size['height'])) # 写成我们需要截取的位置坐标 print('four: ', rangle) i = Image.open(r"C:\Users\86138\Desktop\2020.11.3星际游慢充\star_game\media\car_code.png") # 打开截图 frame4 = i.crop(rangle) # 使用Image的crop函数,从截图中再次截取我们需要的区域 rgb_im = frame4.convert('RGB') rgb_im.save(r'C:\Users\86138\Desktop\2020.11.3星际游慢充\star_game\media\car_save.png') # 保存我们接下来的验证码图片 进行打码 # 打码 im = open(r'C:\Users\86138\Desktop\2020.11.3星际游慢充\star_game\media\car_save.png', 'rb').read() data = chao_ji_ing.PostPic(im, 1005) print(data) if data['pic_str'] == '': statue = {'STATUE': 404, 'MSG': '系统超时'} chao_ji_ing.ReportError(data['pic_id']) print(statue) code = data['pic_str'] # code = 'pgov' try: driver.find_element_by_id('rand').send_keys(code) # 验证码输入 except Exception as e: statue = {'STATUE': 400, 'MESSAGE': '验证码输入有误'} chao_ji_ing.ReportError(data['pic_id']) print(statue) # 提交 time.sleep(0.5) try:
class SoHuWosrd(object): '''搜狐刀剑英雄充值入口''' def __init__(self): # 驱动参数 self.chao_ji_ing = Chaojiying_Client( 'nap2017', 'qweasdzxc', '909537') # 用户中心>>软件ID 生成一个替换 96001 self.options = webdriver.ChromeOptions() self.options.add_argument('--user-agent={}'.format(ua_pond)) self.options.add_argument('window-size=1920x1080') # 指定浏览器分辨率 self.options.add_argument('--headless') # 无界面模式 self.options.add_argument('--disable-gpu') # 隐藏gpu界面 # self.options.add_argument('--proxy-server=http://{}'.format(ip_port())) # ip 代理 self.driver = webdriver.Chrome('/usr/local/bin/chromedriver', chrome_options=self.options) # 基本参数 self.url = 'http://chong.changyou.com/djbase/cardpwdUnLoginInit.do?gameType=2' def parse(self, an, cn, cp): # xss注入参数 # self.driver.find_element_by_id('cn').send_keys(account_number) # 账号 # self.driver.find_element_by_id('confirmcnId').send_keys(account_number) # 确认账号 # self.driver.find_element_by_id('cardNo').send_keys(card_number) # 卡号 # self.driver.find_element_by_id('cardPwd').send_keys(card_password) # 密码 self.driver.find_element_by_id('cn').send_keys(an) # 账号 self.driver.find_element_by_id('confirmcnId').send_keys(an) # 确认账号 self.driver.find_element_by_id('cardNo').send_keys(cn) # 卡号 self.driver.find_element_by_id('cardPwd').send_keys(cp) # 密码 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 save(self, statue): # 获取充值结果 print(statue) print(self.driver.title) time.sleep(5) self.driver.quit() return statue 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
int(lo_location['y'] + size['height'])) # 写成我们需要截取的位置坐标 print(rangle) i = Image.open("../media/sohu_sword_code.png") # 打开截图 frame4 = i.crop(rangle) # 使用Image的crop函数,从截图中再次截取我们需要的区域 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)
class PerfectWorld(object): '''完美点券充值入口''' def __init__(self): # 驱动参数 self.chao_ji_ing = Chaojiying_Client( 'nap2017', 'qweasdzxc', '909537') # 用户中心>>软件ID 生成一个替换 96001 self.options = webdriver.ChromeOptions() self.options.add_argument('--user-agent={}'.format(ua_pond)) self.options.add_argument('window-size=1920x1080') # 指定浏览器分辨率 self.options.add_argument('--headless') # 无界面模式 self.options.add_argument('--disable-gpu') # 隐藏gpu界面 # self.options.add_argument('--proxy-server=http://{}'.format(ip_port())) # ip 代理 self.driver = webdriver.Chrome('/usr/local/bin/chromedriver', chrome_options=self.options) self.url = 'https://pay.wanmei.com/new/newpay.do?op=prepay&gametype=93' def click(self, account, password): try: # self.driver.find_element_by_id('username').send_keys(perfect_login('账号')) self.driver.find_element_by_id('username').send_keys(account) # self.driver.find_element_by_id('passwd').send_keys(perfect_login('密码')) self.driver.find_element_by_id('passwd').send_keys(password) self.driver.find_element_by_xpath( '//*[@id="wanmeiCaptcha_0"]/div/p').click() # 点选验证码 print('Click on the success') except Exception as e: # print('没订上', e) statue = {'STATUE': 404, 'MSG': '没订上', 'DATA': e} return statue 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) # return statue def input(self, an, cn, cp): '''登陆后操作''' time.sleep(2) # 充值 try: element = self.driver.find_element_by_xpath( '//em[text()="完美一卡通"]') # 点击卡密进行充值 self.driver.execute_script("arguments[0].click();", element) print('-----登陆已经点击-----') except Exception as e: statue = {'STATUE': 400, 'MESSAGE': '没点击登陆 -.= ', 'DATA': e} # print(statue) return statue # 输入参数 try: self.driver.find_element_by_name('username').clear() # self.driver.find_element_by_name('username').send_keys(account_number) # 输入账号 self.driver.find_element_by_name('username').send_keys(an) # 输入账号 self.driver.find_element_by_name('username2').clear() # self.driver.find_element_by_name('username2').send_keys(account_number) # 再次输入账号 self.driver.find_element_by_name('username2').send_keys( an) # 再次输入账号 except Exception as e: statue = {'STATUE': 400, 'MESSAGE': '卡号错误', 'DATA': e} # print(statue) return statue try: # self.driver.find_element_by_name('cardnumber').send_keys(card_number) # 卡号 self.driver.find_element_by_name('cardnumber').send_keys(cn) # 卡号 # self.driver.find_element_by_name('cardpasswd').send_keys(card_password) # 卡密 self.driver.find_element_by_name('cardpasswd').send_keys(cp) # 卡密 except Exception as e: statue = {'STATUE': 400, 'MESSAGE': '卡号或卡密错误', 'DATA': e} # print(statue) return statue def cut_img(self): # 截图 try: aa = self.driver.find_element_by_xpath( '//div[@class="mCaptchaSlideBorder"]') ActionChains(self.driver).click_and_hold(aa).perform() except Exception as e: # print('点击滑块出现问题') statue = {'STATUE': 400, 'MESSAGE': '点击滑块出现问题', 'DATA': e} return statue return aa def save_img(self): try: # 显示小滑块 display_element = self.driver.find_element_by_xpath( '//*[@id="captchasDivId"]/div/div[2]/div[2]/div[1]') self.driver.execute_script("arguments[0].style=arguments[1]", display_element, "display: block;") pic_url = self.driver.save_screenshot( '/www/wwwroot/www.stargame.com/media/2perfect2.png') print("%s:截图成功!" % pic_url) imgelement = self.driver.find_element_by_xpath( '//*[@id="sliderImgContainer"]/div[1]') # 定位验证码 location_dict = imgelement.location # 获取验证码x,y轴坐标 print('lo: ', location_dict) # lo_location = {'x': 385, 'y': 439} # 显示 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/2perfect2.png') # 打开截图 frame4 = i.crop(rangle) # 使用Image的crop函数,从截图中再次截取我们需要的区域 rgb_im = frame4.convert('RGB') rgb_im.save( '/www/wwwroot/www.stargame.com/media/2perfect_save2.png') except Exception as e: # print('保存失败') statue = {'STATUE': 400, 'MESSAGE': '保存失败', 'DATA': e} return statue def fight_code(self, aa): t = self.driver.title print(t, type(t)) if self.driver.title == '登录 - 完美世界通行证': print('进入失败') else: print('登陆充值界面成功!') try: # 打滑块 json_data = lianzhong( '/www/wwwroot/www.stargame.com/media/2perfect_save2.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, 'MESSAGE': '滑块请求失败', 'DATA': e} return statue try: x = int(x_offset) except Exception as e: lianzhong_wrong(value_id) # print('位置返回为空', e) statue = {'STATUE': 400, 'MESSAGE': '位置返回为空', 'DATA': e} return statue try: # 滑动的动作链 ActionChains(self.driver).click_and_hold(aa).perform() time.sleep(1) # ActionChains(driver).move_by_offset(xoffset=50, yoffset=0).perform() 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, 'MESSAGE': '滑动失败', 'DATA': e} return statue try: self.driver.find_element_by_class_name('btn01').click() # 点击充值 except Exception as e: # print('点击失败', e) statue = {'STATUE': 400, 'MESSAGE': '点击失败', 'DATA': e} return statue try: # driver.find_element_by_class_name('btn05').click() # 再次确认充值 self.driver.find_element_by_xpath( '//*[@id="div1"]/div/center/a[1]').click() # 再次确认充值 except Exception as e: # lianzhong_wrong(value_id) # print(e) statue = {'STATUE': 400, 'MESSAGE': '二次确认充值失败', 'DATA': e} return statue st = self.driver.find_element_by_class_name('other_error').text if st == '该卡已被使用': statue = {'STATUE': 400, 'MESSAGE': st} # print(statue) return statue def save(self): print(self.driver.title) time.sleep(5) self.driver.quit() 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
class SoHu(object): '''搜狐充值入口''' def __init__(self, choice): # 驱动参数 self.chao_ji_ing = Chaojiying_Client('nap2017', 'qweasdzxc', '909537') # 用户中心>>软件ID 生成一个替换 96001 self.options = webdriver.ChromeOptions() self.options.add_argument('--user-agent={}'.format(ua_pond)) self.options.add_argument('window-size=1920x1080') # 指定浏览器分辨率 self.options.add_argument('--headless') # 无界面模式 self.options.add_argument('--disable-gpu') # 隐藏gpu界面 # self.options.add_argument('--proxy-server=http://{}'.format(ip_port())) # ip 代理 self.driver = webdriver.Chrome('/usr/local/bin/chromedriver',chrome_options=self.options) # 基本参数 self.url = 'http://chong.changyou.com/' self.choice_game = choice_sever_SOHU(choice) # 选择游戏 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 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 def save(self, statue): # 获取充值结果 print(statue) print(self.driver.title) time.sleep(5) self.driver.quit() return statue 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()
class GoldenHill(object): '''金山充值入口''' # 存储图片位置需修改为abs path def __init__(self, cchoice): '''驱动参数''' # 用户中心>>软件ID 生成一个替换 96001 self.chao_ji_ing = Chaojiying_Client('nap2017', 'qweasdzxc', '909537') # 实例化 self.options = webdriver.ChromeOptions() # ua池 self.options.add_argument('--user-agent={}'.format(ua_pond)) # 指定浏览器分辨率 self.options.add_argument('window-size=1920x1080') # 无界面模式 self.options.add_argument('--headless') # 隐藏gpu界面 self.options.add_argument('--disable-gpu') # ip池 # self.options.add_argument('--proxy-server=http://{}'.format(ip_port())) # ip 代理 # 驱动器 self.driver = webdriver.Chrome('/usr/local/bin/chromedriver', chrome_options=self.options) # 基本参数 # self.url = 'https://charge.xoyo.com/pay?item={}&way=kcard'.format(gh_value(cchoice)) self.url = 'https://charge.xoyo.com/pay?item={}&way=kcard'.format(cchoice) def parse(self, data, choice, an, cn, cp): try: # xss注入参数 if self.url == 'https://charge.xoyo.com/pay?item=jx3&way=kcard': # 剑网3 # if gh_value(data) == '0': self.driver.find_element_by_id('pay_account_account').send_keys(an) # 账号 # self.driver.find_element_by_id('pay_account_account').send_keys(account_number) # 账号 self.driver.find_element_by_id('pay_account_repeat_account').send_keys(an) # 确认账号 # self.driver.find_element_by_id('pay_account_repeat_account').send_keys(account_number) # 确认账号 self.driver.find_element_by_xpath('//input[@placeholder="请选择大区"]').click() time.sleep(0.5) # self.driver.find_element_by_xpath(choice_sever('电信一区(点月卡)')).click() self.driver.find_element_by_xpath(choice_sever(choice)).click() # driver.find_element_by_xpath('//li[@id="pay_gateway_z01"]').click() # self.driver.find_element_by_id('pay_kcard_num').send_keys(card_number) # 卡号 self.driver.find_element_by_id('pay_kcard_num').send_keys(cn) # 卡号 # self.driver.find_element_by_id('pay_kcard_pwd').send_keys(card_password) # 密码 self.driver.find_element_by_id('pay_kcard_pwd').send_keys(cp) # 密码 # self.driver.find_element_by_xpath(choice_moneyclassfiy('点卡')).click() # _6 通宝,_1月卡,_2点卡 # self.driver.find_element_by_xpath(choice_moneyclassfiy('点卡')).click() # _6 通宝,_1月卡,_2点卡 self.driver.find_element_by_xpath(choice_moneyclassfiy(data)).click() # _6 通宝,_1月卡,_2点卡 elif self.url == 'https://charge.xoyo.com/pay?item=jx2&way=kcard': # 剑网2 # elif gh_value(data) == 'jx2': # q = choice_sever_jw2('新传区') q = choice_sever_jw2(choice) self.driver.find_element_by_xpath(q).click() self.driver.find_element_by_xpath('//span[text()="金山一卡通支付"]').click() self.driver.find_element_by_id('pay_account_account').send_keys(an) # 账号 # self.driver.find_element_by_id('pay_account_account').send_keys(account_number) # 账号 # self.driver.find_element_by_id('pay_account_repeat_account').send_keys(account_number) # 确认账号 self.driver.find_element_by_id('pay_account_repeat_account').send_keys(an) # 确认账号 # self.driver.find_element_by_id('pay_kcard_num').send_keys(card_number) # 卡号 self.driver.find_element_by_id('pay_kcard_num').send_keys(cn) # 卡号 # self.driver.find_element_by_id('pay_kcard_pwd').send_keys(card_password) # 密码 self.driver.find_element_by_id('pay_kcard_pwd').send_keys(cp) # 密码 try: # self.driver.find_element_by_xpath(choice_moneyclassfiy_jw2('大银票')).click() # 包周/包月, 记点, 大银票 self.driver.find_element_by_xpath(choice_moneyclassfiy_jw2(data)).click() # 包周/包月, 记点, 大银票 except: print('你是免费区或新传区') elif self.url == 'https://charge.xoyo.com/pay?item=jx2wz&way=kcard': # 剑网2外传 # elif gh_value(data) == 'jx2wz': # self.driver.find_element_by_id('pay_account_account').send_keys(account_number) # 账号 # self.driver.find_element_by_id('pay_account_repeat_account').send_keys(account_number) # 确认账号 # self.driver.find_element_by_id('pay_kcard_num').send_keys(card_number) # 卡号 # self.driver.find_element_by_id('pay_kcard_pwd').send_keys(card_password) # 密码 self.driver.find_element_by_id('pay_account_account').send_keys(an) # 账号 self.driver.find_element_by_id('pay_account_repeat_account').send_keys(an) # 确认账号 self.driver.find_element_by_id('pay_kcard_num').send_keys(cn) # 卡号 self.driver.find_element_by_id('pay_kcard_pwd').send_keys(cp) # 密码 elif self.url == 'https://charge.xoyo.com/pay?item=jxsj2&way=kcard': # 剑侠世界 # elif gh_value(data) == 'jxsj2': self.driver.find_element_by_id('pay_account_account').send_keys(an) # 账号 # self.driver.find_element_by_id('pay_account_account').send_keys(account_number) # 账号 # self.driver.find_element_by_id('pay_account_repeat_account').send_keys(account_number) # 确认账号 self.driver.find_element_by_id('pay_account_repeat_account').send_keys(an) # 确认账号 self.driver.find_element_by_xpath('//input[@placeholder="请选择大区"]').click() time.sleep(0.5) # self.driver.find_element_by_xpath(choice_sever_jxsj('绿色区')).click() self.driver.find_element_by_xpath(choice_sever_jxsj(choice)).click() # self.driver.find_element_by_id('pay_kcard_num').send_keys(card_number) # 卡号 self.driver.find_element_by_id('pay_kcard_num').send_keys(cn) # 卡号 # self.driver.find_element_by_id('pay_kcard_pwd').send_keys(card_password) # 密码 self.driver.find_element_by_id('pay_kcard_pwd').send_keys(cp) # 密码 elif self.url == 'https://charge.xoyo.com/pay?item=jx&way=kcard': # 剑网1 # elif gh_value(data) == 'jx': # qq = choice_sever_jx('2010区') qq = choice_sever_jx(choice) self.driver.find_element_by_xpath(qq).click() self.driver.find_element_by_xpath('//span[text()="金山一卡通支付"]').click() self.driver.find_element_by_id('pay_account_account').send_keys(an) # 账号 # self.driver.find_element_by_id('pay_account_account').send_keys(account_number) # 账号 self.driver.find_element_by_id('pay_account_repeat_account').send_keys(an) # 确认账号 # self.driver.find_element_by_id('pay_account_repeat_account').send_keys(account_number) # 确认账号 self.driver.find_element_by_id('pay_kcard_num').send_keys(cn) # 卡号 # self.driver.find_element_by_id('pay_kcard_num').send_keys(card_number) # 卡号 self.driver.find_element_by_id('pay_kcard_pwd').send_keys(cp) # 密码 # self.driver.find_element_by_id('pay_kcard_pwd').send_keys(card_password) # 密码 try: self.driver.find_element_by_xpath(choice_money_jx(data)).click() # 包时, 记点, 金币 # self.driver.find_element_by_xpath(choice_money_jx('金币')).click() # 包时, 记点, 金币 except: print('你是免费区或经典区或2010') elif self.url == 'https://charge.xoyo.com/pay?item=cs&way=kcard': # 反恐行动 # elif gh_value(data) == 'cs': # self.driver.find_element_by_id('pay_account_account').send_keys(account_number) # 账号 self.driver.find_element_by_id('pay_account_account').send_keys(an) # 账号 # self.driver.find_element_by_id('pay_account_repeat_account').send_keys(account_number) # 确认账号 self.driver.find_element_by_id('pay_account_repeat_account').send_keys(an) # 确认账号 self.driver.find_element_by_xpath('//input[@placeholder="请选择大区"]').click() time.sleep(0.5) # self.driver.find_element_by_id(choice_sever_cs('电信区')).click() self.driver.find_element_by_id(choice_sever_cs(choice)).click() # self.driver.find_element_by_id('pay_kcard_num').send_keys(card_number) # 卡号 self.driver.find_element_by_id('pay_kcard_num').send_keys(cn) # 卡号 self.driver.find_element_by_id('pay_kcard_pwd').send_keys(cp) # 密码 # self.driver.find_element_by_id('pay_kcard_pwd').send_keys(card_password) # 密码 elif self.url == 'https://charge.xoyo.com/pay?item=fs&way=kcard': # 封神榜 元宝区 # elif gh_value(data) == 'fs': self.driver.find_element_by_id('undefined_fs').click() self.driver.find_element_by_xpath('//span[text()="金山一卡通支付"]').click() self.driver.find_element_by_id('pay_account_account').send_keys(an) # 账号 # self.driver.find_element_by_id('pay_account_account').send_keys(account_number) # 账号 self.driver.find_element_by_id('pay_account_repeat_account').send_keys(an) # 确认账号 # self.driver.find_element_by_id('pay_account_repeat_account').send_keys(account_number) # 确认账号 self.driver.find_element_by_id('pay_kcard_num').send_keys(cn) # 卡号 # self.driver.find_element_by_id('pay_kcard_num').send_keys(card_number) # 卡号 self.driver.find_element_by_id('pay_kcard_pwd').send_keys(cp) # 密码 # self.driver.find_element_by_id('pay_kcard_pwd').send_keys(card_password) # 密码 elif self.url == 'https://charge.xoyo.com/pay?item=fsib&way=kcard': # 封神榜 通宝区 # elif gh_value(data) == 'fsib': self.driver.find_element_by_id('undefined_fsib').click() self.driver.find_element_by_xpath('//span[text()="金山一卡通支付"]').click() self.driver.find_element_by_id('pay_account_account').send_keys(an) # 账号 # self.driver.find_element_by_id('pay_account_account').send_keys(account_number) # 账号 self.driver.find_element_by_id('pay_account_repeat_account').send_keys(an) # 确认账号 # self.driver.find_element_by_id('pay_account_repeat_account').send_keys(account_number) # 确认账号 self.driver.find_element_by_id('pay_kcard_num').send_keys(cn) # 卡号 # self.driver.find_element_by_id('pay_kcard_num').send_keys(card_number) # 卡号 self.driver.find_element_by_id('pay_kcard_pwd').send_keys(cp) # 密码 # self.driver.find_element_by_id('pay_kcard_pwd').send_keys(card_password) # 密码 elif self.url == 'https://charge.xoyo.com/pay?item=cq&way=kcard': # 春秋Q传 self.driver.find_element_by_id('pay_account_account').send_keys(an) # 账号 # self.driver.find_element_by_id('pay_account_account').send_keys(account_number) # 账号 self.driver.find_element_by_id('pay_account_repeat_account').send_keys(an) # 确认账号 # self.driver.find_element_by_id('pay_account_repeat_account').send_keys(account_number) # 确认账号 self.driver.find_element_by_xpath('//input[@placeholder="请选择大区"]').click() time.sleep(0.5) # self.driver.find_element_by_id(choice_sever_cqqz('12-45区电信')).click() self.driver.find_element_by_id(choice_sever_cqqz(choice)).click() self.driver.find_element_by_id('pay_kcard_num').send_keys(cn) # 卡号 # self.driver.find_element_by_id('pay_kcard_num').send_keys(card_number) # 卡号 self.driver.find_element_by_id('pay_kcard_pwd').send_keys(cp) # 密码 # self.driver.find_element_by_id('pay_kcard_pwd').send_keys(card_password) # 密码 self.driver.execute_script('scrollTo(0,500)') # 向下滚动 # time.sleep(sleep_time()) self.driver.find_element_by_id('create_order').click() # 立即充值 time.sleep(1.7) except: statue = {'STATUE': 404, 'MSG': '系统超时'} return statue 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 save(self, statue): # 获取充值结果 print(statue) print(self.driver.title) time.sleep(5) self.driver.quit() return statue def run(self, data, choice, an, cn, cp): time.sleep(sleep_time()) self.driver.get(self.url) # 打开网页 self.parse(data, choice, an, cn, cp) data = self.fight() a = self.save(data) return a
class DOTA2(object): '''dota2充值入口''' def __init__(self): # 驱动参数 self.chao_ji_ing = Chaojiying_Client('nap2017', 'qweasdzxc', '909537') # 用户中心>>软件ID 生成一个替换 96001 self.options = webdriver.ChromeOptions() self.options.add_argument('--user-agent={}'.format(ua_pond)) self.options.add_argument('window-size=1920x1080') # 指定浏览器分辨率 self.options.add_argument('--headless') # 无界面模式 self.options.add_argument('--disable-gpu') # 隐藏gpu界面 # self.options.add_argument('--proxy-server=http://{}'.format(ip_port())) # ip 代理 self.driver = webdriver.Chrome('/usr/local/bin/chromedriver', chrome_options=self.options) # 基本参数 self.url = 'https://pay.wanmei.com/new/dota2/index.do?inGame=0' def parse(self, an, cn, cp): try: self.driver.find_element_by_id('pay3').click() # 选择完美一卡通 time.sleep(0.5) # num = perfect_number('账号') self.driver.find_element_by_id('username').send_keys(an) # 账号 # self.driver.find_element_by_id('username').send_keys(num) # 账号 self.driver.find_element_by_id('username2').send_keys(an) # 再次账号 # self.driver.find_element_by_id('username2').send_keys(num) # 再次账号 self.driver.find_element_by_id('cardnumber').send_keys(cn) # 卡号 # self.driver.find_element_by_id('cardnumber').send_keys(perfect_topup('卡号')) # 卡号 self.driver.find_element_by_id('cardpassword').send_keys(cp) # 密码 # self.driver.find_element_by_id('cardpassword').send_keys(perfect_topup('卡密')) # 密码 except Exception as e: statue = {'STATUE': 400, 'MESSAGE': '账号密码无法输入'} print(statue) def fight(self): # 验证码截取参数 self.driver.save_screenshot('/www/wwwroot/www.stargame.com/media/dota_code.png') imgelement = self.driver.find_element_by_id('randimg') # 定位验证码 location_dict = imgelement.location # 获取验证码x,y轴坐标 print('lo: ', location_dict) # lo_location = {'x': 545, 'y': 460} # 显示 lo_location = {'x': 996, 'y': 460} # 隐式 size_dict = imgelement.size # 获取验证码的长宽 print('hw: ', size_dict) size = {'height': 25, 'width': 60} rangle = (int(lo_location['x']), int(lo_location['y']), int(lo_location['x'] + size['width']), int(lo_location['y'] + size['height'])) # 写成我们需要截取的位置坐标 print('four: ', rangle) i = Image.open("/www/wwwroot/www.stargame.com/media/dota_code.png") # 打开截图 frame4 = i.crop(rangle) # 使用Image的crop函数,从截图中再次截取我们需要的区域 rgb_im = frame4.convert('RGB') rgb_im.save('../media/dota_save.png') # 保存我们接下来的验证码图片 进行打码 # 打码 im = open('/www/wwwroot/www.stargame.com/media/dota_save.png', 'rb').read() data = self.chao_ji_ing.PostPic(im, 3004) print(data) if data['pic_str'] == '': statue = {'STATUE': 404, 'MSG': '系统超时'} self.chao_ji_ing.ReportError(data['pic_id']) # print(statue) return statue code = data['pic_str'] # code = 'pgov' # if len(code) < 5: # statue = {'STATUE': 400, 'MESSAGE': '验证码返回错误'} # self.chao_ji_ing.ReportError(data['pic_id']) # # print(statue) # return statue try: self.driver.find_element_by_id('rand').send_keys(code) # 验证码输入 except Exception as e: statue = {'STATUE': 400, 'MESSAGE': '验证码输入有误'} self.chao_ji_ing.ReportError(data['pic_id']) # print(statue) return statue # 提交 time.sleep(0.5) try: self.driver.find_element_by_xpath('//a[text()="立即充值"]').click() except Exception as e: statue = {'STATUE': 400, 'MESSAGE': '点击失败'} self.chao_ji_ing.ReportError(data['pic_id']) # print(statue) return statue statue = {'STATUE': 200, 'MESSAGE': '成功'} # print(statue) return statue def save(self, statue): # 获取充值结果 print(statue) print(self.driver.title) time.sleep(5) self.driver.quit() return statue 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