Introduce a simple Python crawler, create a client through Tkinter, when entering the LOL user name to query, you can display the current user's server, the current battle force and the current segment.
Crawl Web page address: http://lol.duowan.com/zdl/
Python version: 2.7
Modules needed: Tkinter urllib2 JSON sys
Instance code:
ImportUrllib2, JSON, threading fromTkinterImport*Importsysreload (SYS) sys.setdefaultencoding ('Utf-8')defGet_zhanji (): Name=Str (et.get ()) URL='http://api.lolbox.duowan.com/api/v2/player/search/?player_name_list=%s&callback= jQuery111200161216930093' '95033_1470488155157&_=1470488155158'%Name Res=urllib2.urlopen (URL) HTML= Res.read () [44:-1] PrintHTML Zhanji= json.loads (HTML) [u'player_list'] T.delete (0.0, END) forIinchZhanji:Print 'Server:%s Current Battle Force:%s'% (i['Game_zone']['alias'], i['Box_score']) Print 'current Dan:%s'% (i['Tier_rank']['Tier']['FULL_NAME_CN'] + i['Tier_rank']['Rank']['name']) #print i[' game_zone ' [' Alias '] #Print Zhangji #Print HTMLT.insert (END,'Server:%s Current Battle Force:%s'% (i['Game_zone']['alias'], i['Box_score']) T.insert (END,'current Dan:%s\n'% (i['Tier_rank']['Tier']['FULL_NAME_CN'] + i['Tier_rank']['Rank']['name']))defRukou ():ifEt.get () = ="': Print 'Please enter the name of the Summoner' Else: Get_zhanji ()#def qidong ():#T1 = Threading. Thread (Target=rukou)#T1.start ()#Get_zhanji ()#Print Len (jquery11120016121693009395033_1470488155157 ()Root=Tk () root.title ('lol record Search') root.geometry () et= Entry (Root, font= ('Song body,') ) Et.grid () b= Button (Root, text='Start Query', Font= ('Song body,'), command=Rukou) B.grid () T= Text (Root, font= ('Song body,')) T.grid () Root.mainloop ()
Interface Effect Display:
Python crawler writes LOL record queries in Python