我正在尝试构建一个gui界面,在这里我可以输入视频的标题,一旦我点击按钮,selenium函数(vidplayer)就会在youtube上查找视频并播放结果页面的第一个。 一切正常,除了当我点击按钮时,selenium功能在我的youtube主页上播放第一个视频,而不是寻找我之前选择的视频
from selenium import webdriver
from tkinter import *
root=Tk()
root.title('Youtube Video Player')
text=Label(root,text="In order to save time and avoid procrastination.\nEnter the name of the video
you have in mind,and by the power of the gods it will play")
text.pack()
input=Entry()
input.pack()
a=str(input.get())
#playing the video with the 'a' variable title on youtube
def vidplayer():
browser=webdriver.Chrome('C:\\Users\\lenovo\\Downloads\\chromedriver')
browser.get('https://www.youtube.com/results?search_query='+a)
video=browser.find_element_by_id('video-title')
video.click()
button=Button(text="Play Video", command=vidplayer)
button.pack()
root.mainloop()
问题是,您在创建entry小部件大约一毫秒后调用
a.get()
,远远早于用户有机会输入任何内容。你知道吗解决方法很简单:在实际需要时获取值,而不是在以下时间之前:
相关问题 更多 >
编程相关推荐