- 论坛徽章:
- 4
|
用Label即可,这段代码是python3的。- # -*- coding: utf-8 -*-
- import urllib.request
- from tkinter import *
- import re
- def getupdates():
- url = 'http://i.youku.com/u/UMzE2OTY2NjUy'
- data = urllib.request.urlopen(url)
- num_pattern = 'videos">.(?P<num>\d{2,4}).'
- time_pattern = 'c_time="(?P<time>\d{4}-\d{2}-\d{2}\s\d{2}.\d{2}.\d{2})'
- video_name_pattern = 'replace="false"'
- for line in data.readlines():
- line = line.strip().decode('utf8')
- try:
- num = re.search(num_pattern,line)
- time = re.search(time_pattern,line)
- video = re.search(video_name_pattern,line)
- if num:
- b = int(num.group('num'))
- Label(tk,text = '大酒神共有%d个视频'%b).pack()
- elif time:
- Label(tk, text = time.group('time')).pack()
- elif video:
- a = line.find('title')
- Label(tk, text = line[a+7:-3]).pack()
- except:
- pass
- tk = Tk()
- tk.title('09 dota update')
- tk.geometry('600x600')
- Label(tk,text = 'this is used for collecting 09 dota video updates').pack()
- Button(tk,text = 'get the result',command = getupdates).pack()
- tk.mainloop()
复制代码 |
|