z3xt5r

Untitled

Apr 10th, 2021
962
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from selenium import webdriver
  2. import time
  3. from secrets import username, password
  4.  
  5.  
  6. class bot():
  7.     def __init__(self):
  8.         self.song = input('Enter song to play: ')
  9.  
  10.         self.driver = webdriver.Chrome()
  11.  
  12.     def login(self):
  13.         self.driver.get('https://accounts.spotify.com/en/login')
  14.         time.sleep(2)
  15.  
  16.         email = self.driver.find_element_by_xpath('//*[@id="login-username"]')
  17.         password_fill = self.driver.find_element_by_xpath(
  18.             '//*[@id="login-password"]')
  19.  
  20.         email.send_keys(username)
  21.         password_fill.send_keys(password)
  22.  
  23.         self.click_login()
  24.  
  25.         self.click_webplayer()
  26.  
  27.     def click_webplayer(self):
  28.         time.sleep(2)
  29.         try:
  30.             webplayer = self.driver.find_element_by_xpath(
  31.                 '//*[@id="app"]/body/div/div[2]/div/div/div[4]/div/a')
  32.             webplayer.click()
  33.         except:
  34.             self.click_webplayer()
  35.  
  36.     def search_song(self):
  37.         self.driver.get('https://open.spotify.com/search/')
  38.         self.fill_search()
  39.         self.click_play()
  40.  
  41.     def fill_search(self):
  42.         time.sleep(1)
  43.         try:
  44.             search_bar = self.driver.find_element_by_xpath(
  45.                 '//*[@id="main"]/div/div[2]/div[1]/header/div[3]/div/div/input')
  46.  
  47.             search_bar.send_keys(self.song)
  48.         except:
  49.             self.fill_search()
  50.  
  51.     def click_play(self):
  52.         time.sleep(1)
  53.         try:
  54.             play = self.driver.find_element_by_xpath(
  55.                 '//*[@id="searchPage"]/div/div/section[2]/div[2]/div/div/div/div[2]/div[1]/div/div[1]/div[1]/img')
  56.             play.click()
  57.         except:
  58.             self.click_play()
  59.  
  60.     def click_login(self):
  61.         time.sleep(1)
  62.         try:
  63.             login_button = self.driver.find_element_by_xpath(
  64.                 '//*[@id="login-button"]')
  65.             login_button.click()
  66.         except:
  67.             self.click_login()
  68.  
  69.  
  70. spotify_bot = bot()
  71. spotify_bot.login()
  72. spotify_bot.search_song()
  73.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×