In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces the python visual crawler interface of the weather query example analysis, the article is very detailed, has a certain reference value, interested friends must read it!
The execution results are as follows:
From tkinter import * import urllib.requestimport gzipimport jsonfrom tkinter import messageboxroot = Tk () def main (): # input window root.title ('Python Learning Exchange Group: 973783996') # window title Label (root, text=', please enter city') .grid (row=0, column=0) # set label and adjust position enter = Entry (root) # input box enter.grid (row=0, column=1, padx=20, pady=20) # adjust position enter.delete (0 END) # clear input box enter.insert (0 'Python Learning Communication Group: 973783996') # set the default text # enter_text = enter.get () # get the content of the input box running = 1 def get_weather_data (): # get the website data city_name = enter.get () # get the content of the input box url1 =' http://wthrcdn.etouch.cn/weather_mini?city=' + urllib.parse.quote (city_name) Url2 = 'http://wthrcdn.etouch.cn/weather_mini?citykey=101010100' # URL 1 only need to enter the city name URL 2 needs to enter the city code # print (url1) weather_data = urllib.request.urlopen (url1). Read () # read web page data weather_data = gzip.decompress (weather_data) .decode ('utf-8') # decompress web page data weather_dict = json.loads (weather_data) # convert json data to dict data if weather_dict.get (' desc') = 'invilad-citykey': print (messagebox.askokcancel ("xing") "you entered the wrong city name. Or your city is not included in the weather center ") else: # print (messagebox.askokcancel ('xing','bingguo')) show_data (weather_dict, city_name) def show_data (weather_dict City_name): # display data forecast = weather_dict.get ('data'). Get (' forecast') # get data block root1 = Tk () # pair window root1.geometry ('650x280') # modify window size root1.title (city_name + 'weather conditions') # sub window title # set date list for i in range (5): # put the data for each day in the list LANGS = [(date' [I] .get ('list)) Date), (str [I]. Get ('fengxiang'),' wind direction'), (str (wind [I]. Get ('wind)),' wind scale'), (minimum [I]. Get ('high'),' highest temperature'), (minimum [I]. Get ('low'),' minimum temperature') (type' [I] .get ('type'),' weather')] group = LabelFrame (root1, text=' weather conditions', padx=0, pady=0) # frame group.pack (padx=11, pady=0, side=LEFT) # place frame for lang, value in LANGS: # put data into the frame c = Label (group, text=value +':'+ lang) c.pack (anchor=W) Label (root1 Text=' Today'+ weather_dict.get ('data'). Get (' ganmao'), fg='green') .place (StarMan 40, yearly 20, height=40) # warm reminder Label (root1, text= "StarMan: 49star.com", fg= "green", bg= "yellow") .place (xylene 10, Yale 255, width=125, height=20) # author's website Button (root1, text=' confirm and exit', width=10, command=root1.quit) .place (Xerox 500 Yellow230, width=80, height=40) # exit button root1.mainloop () # layout button Button (root, text= "confirm", width=10, command=get_weather_data)\ .grid (row=3, column=0, sticky=W, padx=10, pady=5) Button (root, text=' exit', width=10, command=root.quit)\ .grid (row=3, column=1, sticky=E, padx=10) Pady=5) if running = = 1: root.mainloop () if _ _ name__ = ='_ _ main__': main () above are all the contents of the article "sample Analysis of Weather query in python Visual Crawler Interface" Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.