2017-09-04 27 views
-2

这项计划是为了刮去YouTube播放列表Tkinter的程序,播放列表刮板

# coding=utf-8 


from tkinter import * 
from urllib.request import urlopen as uReq 
from bs4 import BeautifulSoup as soup 

class YoutubeScraper: 

    def __init__(self,master): 
     label = Label(master, text='Youtube Playlist scraper!') 
     label.pack() 
     frame = Frame(master) 
     frame.pack() 


     self.runButton = Button(frame, text='Print Message', command=runProgram) 
     self.runButton.pack(side=LEFT) 

     self.quitButton = Button(frame, text='QUIT', command=frame.quit) 
     self.quitButton.pack(side=LEFT) 

    def runProgram(self): 
     print("This works") 

     # my_url = 'https://www.youtube.com/watch?v=P8bx4nits-o&index=5&list=PL6gx4Cwl9DGAjkwJocj7vlc_mFU-4wXJq' 

     # uClient = uReq(my_url) 
     # page_html = uClient.read() 
     # uClient.close() 

     # # Cleaning up the HTML 
     # page_soup = soup(page_html, 'html.parser') 

     # # Grabs each product! 
     # containers = page_soup.findAll('li', {'class': 'yt-uix-scroller-scroll-unit'}) 

     # # writes data to a file! 
     # fileName = 'Pygame.txt' 
     # f = open(fileName, 'w') 

     # for container in containers: 
     #  title = container.a.h4.string 
     #  link = container.a['href'] 
     #  href = 'https://youtube.com/' + link 
     #  print(title) 
     #  print(href) 

     #  f.write(title + " " + href + '\n\n') 
     # f.close() 

root = Tk() 
program_run = YoutubeScraper(root) 
root.mainloop() 

我需要帮助得到这个工作的所有链接,即时通讯仍然试图环绕功能我的大脑,我得到一个错误我的runProgram函数没有定义! 我不明白BC甚至与通过作为函数定义它仍然给我一个错误,它没有被定义!

回答

1

就像您需要使用'self'来引用其他类中的属性......例如使用self.runButton而不是runButton,您需要使用self来引用类中的函数。

self.runButton = Button(frame, text='Print Message', command=self.runProgram) 
相关问题