首页 > 代码库 > GUI加爬虫

GUI加爬虫

# - *-coding:utf-8-*-
from Tkinter import *
from ScrolledText import ScrolledText #滚动文本框
import urllib,re
url_name=[]
a=1
def get(id):
global a
url=‘http://www.budejie.com/video/‘+str(a)
varl.set(‘已经获取到第%s页的视频‘%(a))
a+=1
print url
html = urllib.urlopen(url).read()
reg=re.compile(r‘data-mp4="(.*?)"‘)
vedio=re.findall(reg,html)
regl=re.compile(r‘<div class="j-r-list-c-desc">(.*?)</div>‘,re.S)
name=re.findall(regl,html)
for i,k in zip(name,vedio):
url_name.append([i,k])
id=1
def write():
global id
while id<100:
get(id)
for i in url_name:
text.insert(END,str(id)+‘.‘+i[0]+‘\n‘+i[1])
url_name.pop(0)
id+=1
root = Tk()
root.title(‘我的小盒子‘)
root.geometry(‘+600+100‘)
text=ScrolledText(root,font=(‘微软雅黑‘,10))
text.grid()
button=Button(root,text="开始爬取",font=(‘黑体‘,10),command=write)
button.grid()
varl=StringVar()
label= Label(root,font=(‘黑体‘,10),fg=‘red‘,textvariable=varl)
label.grid()
varl.set(‘准备中..‘)

root.mainloop()

GUI加爬虫