Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from selenium import webdriver
- import time
- from secrets import username, password
- class bot():
- def __init__(self):
- self.song = input('Enter song to play: ')
- self.driver = webdriver.Chrome()
- def login(self):
- self.driver.get('https://accounts.spotify.com/en/login')
- time.sleep(2)
- email = self.driver.find_element_by_xpath('//*[@id="login-username"]')
- password_fill = self.driver.find_element_by_xpath(
- '//*[@id="login-password"]')
- email.send_keys(username)
- password_fill.send_keys(password)
- self.click_login()
- self.click_webplayer()
- def click_webplayer(self):
- time.sleep(2)
- try:
- webplayer = self.driver.find_element_by_xpath(
- '//*[@id="app"]/body/div/div[2]/div/div/div[4]/div/a')
- webplayer.click()
- except:
- self.click_webplayer()
- def search_song(self):
- self.driver.get('https://open.spotify.com/search/')
- self.fill_search()
- self.click_play()
- def fill_search(self):
- time.sleep(1)
- try:
- search_bar = self.driver.find_element_by_xpath(
- '//*[@id="main"]/div/div[2]/div[1]/header/div[3]/div/div/input')
- search_bar.send_keys(self.song)
- except:
- self.fill_search()
- def click_play(self):
- time.sleep(1)
- try:
- play = self.driver.find_element_by_xpath(
- '//*[@id="searchPage"]/div/div/section[2]/div[2]/div/div/div/div[2]/div[1]/div/div[1]/div[1]/img')
- play.click()
- except:
- self.click_play()
- def click_login(self):
- time.sleep(1)
- try:
- login_button = self.driver.find_element_by_xpath(
- '//*[@id="login-button"]')
- login_button.click()
- except:
- self.click_login()
- spotify_bot = bot()
- spotify_bot.login()
- spotify_bot.search_song()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement