Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- from selenium.webdriver import Chrome
- from selenium.webdriver.common.keys import Keys
- from selenium.webdriver.firefox.options import Options
- from selenium.webdriver.common.action_chains import ActionChains
- # spotify credentials
- USERNAME = ''
- PASSWORD = ''
- URL_CONNECT= "https://accounts.spotify.com/fr-FR/login?continue=https:%2F%2Fwww.spotify.com%2Ffr%2Faccount%2Foverview%2F"
- URL_PLAYLIST = 'https://open.spotify.com/user/tapoteur/playlist/49yHl6MyiZSlB4pX0WFcB5' # Here change with out playlist
- NUMBER_OF_TRACKS = 4 # number of tracks in our playlist
- DURATION_OF_TRACK = 31 # 31 sec
- # setup driver
- opts = Options()
- opts.set_headless()
- assert opts.headless # operating in headless mode
- browser = Chrome(options=opts)
- # Connect
- browser.get(URL_CONNECT)
- user_form = browser.find_element_by_xpath('//*[@id="login-username"]')
- password_form = browser.find_element_by_xpath('//*[@id="login-password"]')
- user_form.send_keys(USERNAME)
- password_form.send_keys(PASSWORD)
- password_form.send_keys(Keys.ENTER)
- # browser.implicitly_wait(50)
- import time
- time.sleep(10)
- browser.get('http://google.fr')
- browser.get(URL_PLAYLIST)
- # browser.get('http://google.fr')
- time.sleep(2)
- while True:
- 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')
- 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')
- actionChains = ActionChains(browser)
- actionChains.double_click(first_track)
- play_track.click()
- # first_track.click()
- #
- # play_button = browser.find_element_by_xpath('//*[@id="main"]/div/div[5]/footer/div/div[2]/div/div[1]/button[3]')
- # play_button.click()
- # play_button.click()
- time.sleep(NUMBER_OF_TRACKS * DURATION_OF_TRACK + 1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement