學校實訓的第三天(2)
阿新 • • 發佈:2018-12-18
王者榮耀助手(控制檯輸出的) 話不多說,直接上程式碼:
import requests def init(): #1.準備頭部資訊 head = {'Accept-Charset': 'UTF-8', 'Accept-Encoding': 'gzip,deflate', 'User-Agent': 'Dalvik/2.1.0 (Linux; U; Android 6.0.1; MI 5 MIUI/V8.1.6.0.MAACNDI)', 'X-Requested-With': 'XMLHttpRequest', 'Content-type': 'application/x-www-form-urlencoded', 'Connection': 'Keep-Alive', 'Host': 'gamehelper.gm825.com'} #2.準備英雄列表的地址 heros_list_url = 'http://gamehelper.gm825.com/wzry/hero/list?channel_id=90009a&app_id=h9044j&game_id=7622&game_name=%E7%8E%8B%E8%80%85%E8%8D%A3%E8%80%80&vcode=12.0.3&version_code=1203&cuid=2654CC14D2D3894DBF5808264AE2DAD7&ovr=6.0.1&device=Xiaomi_MI+5&net_type=1&client_id=1Yfyt44QSqu7PcVdDduBYQ%3D%3D&info_ms=fBzJ%2BCu4ZDAtl4CyHuZ%2FJQ%3D%3D&info_ma=XshbgIgi0V1HxXTqixI%2BKbgXtNtOP0%2Fn1WZtMWRWj5o%3D&mno=0&info_la=9AChHTMC3uW%2BfY8%2BCFhcFw%3D%3D&info_ci=9AChHTMC3uW%2BfY8%2BCFhcFw%3D%3D&mcc=0&clientversion=&bssid=VY%2BeiuZRJ%2FwaXmoLLVUrMODX1ZTf%2F2dzsWn2AOEM0I4%3D&os_level=23&os_id=dc451556fc0eeadb&resolution=1080_1920&dpi=480&client_ip=192.168.0.198&pdunid=a83d20d8' # 3.顯示英雄列表 show_heros_list(heros_list_url,head) # 11.查詢英雄詳細資訊,輸出 hero_id = input('請輸入查詢英雄的ID:') hero_info_url = 'http://gamehelper.gm825.com/wzry/hero/detail?hero_id='+hero_id+'&channel_id=90009a&app_id=h9044j&game_id=7622&game_name=%E7%8E%8B%E8%80%85%E8%8D%A3%E8%80%80&vcode=12.0.3&version_code=1203&cuid=2654CC14D2D3894DBF5808264AE2DAD7&ovr=6.0.1&device=Xiaomi_MI+5&net_type=1&client_id=1Yfyt44QSqu7PcVdDduBYQ%3D%3D&info_ms=fBzJ%2BCu4ZDAtl4CyHuZ%2FJQ%3D%3D&info_ma=XshbgIgi0V1HxXTqixI%2BKbgXtNtOP0%2Fn1WZtMWRWj5o%3D&mno=0&info_la=9AChHTMC3uW%2BfY8%2BCFhcFw%3D%3D&info_ci=9AChHTMC3uW%2BfY8%2BCFhcFw%3D%3D&mcc=0&clientversion=&bssid=VY%2BeiuZRJ%2FwaXmoLLVUrMODX1ZTf%2F2dzsWn2AOEM0I4%3D&os_level=23&os_id=dc451556fc0eeadb&resolution=1080_1920&dpi=480&client_ip=192.168.0.198&pdunid=a83d20d8' show_hero_info(hero_info_url,head) #18.在繼續 yes = input('繼續查詢輸入y,退出輸入n') if yes == 'y': init() elif yes == 'n': print('END\n'*5) return else: print('你調皮了,請輸入正確指令') init() def show_heros_list(heros_list_url,head): #5.初始化頁面 print('*'*100) print('\t\t\t\t\t\t\t\t歡迎使用王者榮耀盜版助手') print('*'*100,end='\n') print('\t\t\t\t\t\t\t\t--英雄列表--',end='\n') #6.發起請求 response = requests.get(url=heros_list_url,headers=head) if response.status_code ==200: #7.json():返回的json字串 轉換成 json格式的物件 json = response.json() #print(json['request_id']) #8.通過name list獲取value json['name'] flag = 0 for hero in json['list']: #9.格式化字元:%s:插入一個string型別的值 print('ID: %s 英雄名字: %s'%(hero['hero_id'],hero['name']),end='\t\t') #10.當flag遞增到3時,跨行處理,初始為0 flag += 1 if flag == 3: print('\n') flag = 0 else: print('盜版軟體以後請勿使用---------') #顯示查詢英雄的資訊 def show_hero_info(hero_info_url,head): try: #11.查詢英雄資訊,輸出 json = requests.get(url=hero_info_url,headers=head).json() print('查詢英雄:%s 別名:%s'%(json['info']['name'],json['info']['title']),end='\n\n' ) print('歷史介紹:\n %s' %(json['info']['history_intro']),end='\n\n') print('技能: ',end='\n') for skill in json['info']['skill_list']: print('名字: %s \n描述:%s \nTAG:%s'%(skill['name'],skill['description'],skill['tags']), end='\n\n') #12.查詢推薦出裝,並顯示裝備資訊 weapon_list_url = 'http://gamehelper.gm825.com/wzry/equip/list?channel_id=90009a&app_id=h9044j&game_id=7622&game_name=%E7%8E%8B%E8%80%85%E8%8D%A3%E8%80%80&vcode=12.0.3&version_code=1203&cuid=2654CC14D2D3894DBF5808264AE2DAD7&ovr=6.0.1&device=Xiaomi_MI+5&net_type=1&client_id=1Yfyt44QSqu7PcVdDduBYQ%3D%3D&info_ms=fBzJ%2BCu4ZDAtl4CyHuZ%2FJQ%3D%3D&info_ma=XshbgIgi0V1HxXTqixI%2BKbgXtNtOP0%2Fn1WZtMWRWj5o%3D&mno=0&info_la=9AChHTMC3uW%2BfY8%2BCFhcFw%3D%3D&info_ci=9AChHTMC3uW%2BfY8%2BCFhcFw%3D%3D&mcc=0&clientversion=&bssid=VY%2BeiuZRJ%2FwaXmoLLVUrMODX1ZTf%2F2dzsWn2AOEM0I4%3D&os_level=23&os_id=dc451556fc0eeadb&resolution=1080_1920&dpi=480&client_ip=192.168.0.198&pdunid=a83d20d8' weapon_json = requests.get(url=weapon_list_url,headers=head).json() #13.獲取裝備列表 weapon_list = weapon_json['list'] for choice in json['info']['equip_choice']: print('六神裝介紹-%s:\n\t %s'%(choice['title'],choice['description']),end='\n\n') #14.迴圈是推薦裝備列表 totle_price = 0 # 價錢 for equip_weapon in choice['list']: #15.裝備商店的列表 flag = 0 for weapon in weapon_list: #16.在遍歷95件裝備的時候:匹配推薦裝備ID if str(equip_weapon['equip_id']) == weapon['equip_id']: weapon_name = weapon['name'] #獲取裝備名字 weapon_price = weapon['price'] #獲取裝備假期 print('\t\t%s:%s'%(weapon_name,weapon_price)) flag += 1 if flag == 2 : print('\n') flag = 0 totle_price += int(weapon_price) #17.輸出六神裝的總價錢 %d:int print('神裝總價:%d'%(totle_price)) except: print('沒有該英雄,請重新輸入') init() #入口 if __name__ == '__main__': init()