zoukankan      html  css  js  c++  java
  • tkinter + 爬虫 实现影视在线资源系统

    应吾爱朋友现公布代码如下:

    import tkinter as tk
    import requests,re,sys,asyncio
    from tkinter import scrolledtext,END,Y,LEFT,BOTH,messagebox
    import pyperclip,webbrowser
    
    class Video(object):
        def __init__(self,master):
            self.master = master
            self.adict={}
            self.bdict={}
            self.initWidgets()
        def initWidgets(self):
            #菜单点击搜索结果复制到剪切板到浏览器
            menubar = tk.Menu(self.master)
            filemenu = tk.Menu(menubar,tearoff=0) 
            filemenu_1 = tk.Menu(menubar,tearoff=0) 
            menubar.add_cascade(label='关于',menu=filemenu) 
            filemenu.add_command(label='作者:全硕果')
            menubar.add_cascade(label='帮助',menu=filemenu_1)
            filemenu_1.add_command(label='操作',command=self.runing)
            self.master.config(menu = menubar)
    
            tk.Label(self.master,text='影视名称:',font=('Arial,12'),width=15,height=2).place(x=0,y=10)
            tk.Label(self.master,text='搜索结果:',font=('Arial,12'),width=15,height=2).place(x=0,y=50)
            #结果窗口#布局窗口
            frm=tk.Frame(self.master)
            frm.place(x=5,y=80)
            frm_1 = tk.Frame(frm)
            frm_2 = tk.Frame(frm)
            frm_1.pack(side='left')
            frm_2.pack(side='right')
            t_x = tk.Scrollbar(frm)
            t_x.pack(side='right',fill=Y)
            self.rest = tk.Listbox(frm,height=15,width=88,yscrollcommand=t_x.set)
            # rest.place(x=10,y=80)
            self.rest.pack(side=LEFT,fill=BOTH)
            self.rest.bind('<Double-Button-1>',self.get_raw)
            t_x.config(command=self.rest.yview)
            ret = tk.StringVar()
            self.e = tk.Entry(self.master,show=None,textvariable=ret,width=35)
            self.e.place(x=120,y=20)
    
            lable = tk.Label(self.master,text='作者博客:https://www.cnblogs.com/xcsg/',bg='green').place(x=370,y=370)
            tn = tk.Button(self.master,text='搜索',width=20,height=1,command=self.crawl).place(x=450,y=14)
    
    
        def runing(self):
            messagebox.showinfo(title='操作', message='点击搜索结果跳转到浏览器播放')
    
        def _post(self,url, params):
            res = requests.post(url, params=params)
            result =  res.content.decode('utf-8')
            return result 
    
        def get_raw(self, str,event='<Double-Button-1>') -> str:
            windows = tk.Toplevel(self.master)
            windows.title("播放详情")
            windows.geometry('600x200+650+300')
            self.t_y = tk.Scrollbar(windows)
            self.t_y.pack(side='right',fill=Y)
            self.s_tk = tk.Listbox(windows,height=15,width=88,yscrollcommand=self.t_y.set)
            self.s_tk.pack(side=LEFT,fill=BOTH)
            self.s_tk.bind('<Double-Button-1>',self.info_url_)
            self.t_y.config(command=self.s_tk.yview)
            
            ret = requests.get(self.adict[self.rest.curselection()[0]])
            rr = ret.content.decode('utf-8')
            he = re.findall('<li><input type="checkbox" name="copy_sel" value="http://.*/share/.*?" checked="" />(.+?)</li>', rr)
            if he:
                for z,x in enumerate(he):
                    info = x.split("$")[0]+'   影片地址:'+ x.split("$")[1]
                    # #拷贝到剪贴板
                    # pyperclip.copy(x.split("$")[1])
                    # messagebox.showinfo(title='播放地址', message='url:%s 
    已复制至剪贴板' % x.split("$")[1])
                    self.bdict[z] = x.split("$")[1]
                    self.s_tk.insert(END,info)
            else:
                self.s_tk.insert(END,'此影片暂无在线播放')
                # tk.messagebox.showinfo(title='播放地址',message='此影片暂无在线播放')
    
        #浏览器跳转
        def info_url_(self, str,event='<Double-Button-1>') -> str:
            webbrowser.open(self.bdict[self.s_tk.curselection()[0]],new=0)
            
    
        def crawl(self):
            #每次搜索清空
            self.rest.delete(0,len(self.adict))
            name = self.e.get()
            url = 'http://www.zuidazy2.net'
            result = self._post('http://www.zuidazy2.net/index.php?m=vod-search',{'wd': name})
            ni = re.findall('<span class="xing_vb4"><a href="(.+?)" target="_blank">(.+?)<span>(.+?)</span></a></span> <span class="xing_vb5">(.+?)</span> <span class="xing_vb6">(.+?)</span>', result)
    
            for j, i in enumerate(ni):
                self.adict[j] = url + i[0]
                self.rest.insert(END,i[1]+i[2]+'    '+'影片类型:'+i[3]+'    '+'更新时间:'+i[4])
                # rest.insert(END,'		'+'影片类型:'+i[3])
                # rest.insert(END,'		'+'更新时间:'+i[4])
                self.rest.insert(END,)  # 换行骚操作
                self.rest.yview_moveto(j)
                self.rest.update()
    
    if __name__ == "__main__":
        window = tk.Tk()
        window.title('影视搜索')
        # window.geometry("650x400")
        Video(window)
        window.resizable(width=False, height=False)
        window.update_idletasks()
        # width, height = (window.winfo_width(), window.winfo_height())
        width, height = (650,400)
        screenwidth, screenheight = (window.winfo_screenwidth(), window.winfo_screenheight())
        size_loc = '%dx%d+%d+%d' % (width, height, (screenwidth-width)/2, (screenheight-height)/2-30)
        window.geometry(size_loc)
        window.mainloop()
  • 相关阅读:
    初识HTML
    django中这是登录过期时间
    linux之几个重要性能指标
    linux之查看端口占用
    python目录操作整理
    jmeter用户自定义变量的实际使用
    ubuntu安装mysql与配置外网访问
    ubuntu 16.04部署python项目(Nginx+uwsgi+django)
    selenium脚本奇怪报错
    在Ubuntu云服务上部署jenkins
  • 原文地址:https://www.cnblogs.com/xcsg/p/12551592.html
Copyright © 2011-2022 走看看