Advertisement
Guest User

Untitled

a guest
Apr 25th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. import os
  2.  
  3. from selenium.webdriver import Chrome
  4. from selenium.webdriver.common.keys import Keys
  5. from selenium.webdriver.firefox.options import Options
  6. from selenium.webdriver.common.action_chains import ActionChains
  7.  
  8. # spotify credentials
  9. USERNAME = ''
  10. PASSWORD = ''
  11.  
  12.  
  13. URL_CONNECT= "https://accounts.spotify.com/fr-FR/login?continue=https:%2F%2Fwww.spotify.com%2Ffr%2Faccount%2Foverview%2F"
  14. URL_PLAYLIST = 'https://open.spotify.com/user/tapoteur/playlist/49yHl6MyiZSlB4pX0WFcB5' # Here change with out playlist
  15.  
  16. NUMBER_OF_TRACKS = 4 # number of tracks in our playlist
  17. DURATION_OF_TRACK = 31 # 31 sec
  18.  
  19.  
  20. # setup driver
  21. opts = Options()
  22. opts.set_headless()
  23. assert opts.headless # operating in headless mode
  24. browser = Chrome(options=opts)
  25.  
  26.  
  27. # Connect
  28. browser.get(URL_CONNECT)
  29.  
  30. user_form = browser.find_element_by_xpath('//*[@id="login-username"]')
  31. password_form = browser.find_element_by_xpath('//*[@id="login-password"]')
  32.  
  33. user_form.send_keys(USERNAME)
  34. password_form.send_keys(PASSWORD)
  35. password_form.send_keys(Keys.ENTER)
  36.  
  37.  
  38. # browser.implicitly_wait(50)
  39.  
  40. import time
  41. time.sleep(10)
  42. browser.get('http://google.fr')
  43. browser.get(URL_PLAYLIST)
  44. # browser.get('http://google.fr')
  45. time.sleep(2)
  46. while True:
  47. first_track = browser.find_element_by_xpath('//*[@id="main"]/div/div[4]/div[2]/div[1]/div/section/div/div/div[2]/section/ol/div[1]/li')
  48. play_track = browser.find_element_by_xpath('//*[@id="main"]/div/div[4]/div[2]/div[1]/div/section/div/div/div[2]/section/ol/div[1]/li/div[1]/div[1]/svg/path')
  49.  
  50. actionChains = ActionChains(browser)
  51. actionChains.double_click(first_track)
  52. play_track.click()
  53.  
  54. # first_track.click()
  55. #
  56. # play_button = browser.find_element_by_xpath('//*[@id="main"]/div/div[5]/footer/div/div[2]/div/div[1]/button[3]')
  57. # play_button.click()
  58. # play_button.click()
  59.  
  60. time.sleep(NUMBER_OF_TRACKS * DURATION_OF_TRACK + 1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement