Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何播放来自无头Selenium的音乐?_Python_Python 3.x_Selenium_Audio_Google Chrome Headless - Fatal编程技术网

Python 如何播放来自无头Selenium的音乐?

Python 如何播放来自无头Selenium的音乐?,python,python-3.x,selenium,audio,google-chrome-headless,Python,Python 3.x,Selenium,Audio,Google Chrome Headless,我想制作一个应用程序,在headless selenium中播放Spotify音乐,但它根本不播放歌曲。单击按钮的脚本是否正常工作? 这是密码 from selenium import webdriver from selenium.webdriver.chrome.options import Options from selenium.webdriver.common.by import By from selenium.webdriver.common.keys import Keys

我想制作一个应用程序,在headless selenium中播放Spotify音乐,但它根本不播放歌曲。单击按钮的脚本是否正常工作? 这是密码

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
    executable_path = "chromedriver.exe"
    options = Options()
    options.add_argument('--no-sandbox')
    options.add_argument('--no-default-browser-check')
    options.add_argument('--disable-gpu')
    options.add_argument('--disable-extensions')
    options.add_argument('--disable-default-apps')
    options.add_argument('--headless')
    driver = webdriver.Chrome(executable_path=executable_path, options=options)
    driver.get('https://accounts.spotify.com/en/login?continue=https:%2F%2Fopen.spotify.com%2Falbum%2F0KXLHn67Go118RT48pTHXm')
    time.sleep(3)
    driver.find_element_by_name("username").send_keys('my email')
    driver.find_element_by_name("password").send_keys('my password')
    driver.find_element_by_xpath(('//*[@id="login-button"]')).send_keys(Keys.RETURN)
    time.sleep(3)
    driver.execute_script("arguments[0].click();", driver.find_element_by_css_selector('button.btn.btn-green.false'))
当我试着运行它时,我得到了这个

[0113/001403.264:INFO:CONSOLE(0)] "Refused to load the image 'https://www.google.rs/ads/ga-audiences?v=1&aip=1&t=sr&_r=4&tid=UA-5784146-31&cid=434111290.1578870843&jid=1740149161&_v=j79&z=670730096&slf_rd=1&random=2105731225' because it violates the following Content Security Policy directive: "img-src 'self' https://i.imgur.com https://d2mv8tnci56s9d.cloudfront.net https://profile-images.scdn.co https://aci.scdn.co https://graph.facebook.com https://fbcdn-profile-a.akamaihd.net https://scontent.xx.fbcdn.net https://platform-lookaside.fbsbx.com https://www.google.com https://www.google-analytics.com https://stats.g.doubleclick.net data: https://accounts.scdn.co".
", source: https://accounts.spotify.com/en/login?continue=https:%2F%2Fopen.spotify.com%2Falbum%2F0KXLHn67Go118RT48pTHXm (0)
[0113/001407.421:INFO:CONSOLE(0)] "A cookie associated with a cross-site resource at http://google.com/ was set without the `SameSite` attribute. A future release of Chrome will only deliver cookies with cross-site requests if they are set with `SameSite=None` and `Secure`. You can review cookies in developer tools under Application>Storage>Cookies and see more details at https://www.chromestatus.com/feature/5088147346030592 and https://www.chromestatus.com/feature/5633521622188032.", source: https://accounts.spotify.com/en/login?continue=https:%2F%2Fopen.spotify.com%2Falbum%2F0KXLHn67Go118RT48pTHXm (0)
[0113/001407.819:INFO:CONSOLE(0)] "A cookie associated with a cross-site resource at http://google.com/ was set without the `SameSite` attribute. A future release of Chrome will only deliver cookies with cross-site requests if they are set with `SameSite=None` and `Secure`. You can review cookies in developer tools under Application>Storage>Cookies and see more details at https://www.chromestatus.com/feature/5088147346030592 and https://www.chromestatus.com/feature/5633521622188032.", source: https://open.spotify.com/album/0KXLHn67Go118RT48pTHXm (0)
[0113/001409.755:INFO:CONSOLE(0)] "A cookie associated with a cross-site resource at http://subscription.omnithrottle.com/ was set without the `SameSite` attribute. A future release of Chrome will only deliver cookies with cross-site requests if they are set with `SameSite=None` and `Secure`. You can review cookies in developer tools under Application>Storage>Cookies and see more details at https://www.chromestatus.com/feature/5088147346030592 and https://www.chromestatus.com/feature/5633521622188032.", source: https://open.spotify.com/album/0KXLHn67Go118RT48pTHXm (0)
[0113/001410.001:INFO:CONSOLE(0)] "Uncaught (in promise) HarmonyError: Cannot perform command; local player is disabled.", source: https://open.spotify.com/album/0KXLHn67Go118RT48pTHXm (0) ```

你试过使用普通硒元素吗?shimo它使用普通硒元素工作,但不在无头模式下运行时,你是否使用了相同的chrome选项?我猜,其中一个正在阻止播放机(正如最后一个日志所说,
“Uncaught(in promise)HarmonyError:无法执行命令;本地播放机被禁用。”
)您可以安全地忽略
SameSite
警告,它们应该与此问题无关。@Jonah即使没有它们,也无法工作,我猜spotify不允许使用无头浏览器你用普通的selenium试过了吗?@shimo它用普通的selenium工作,但不在无头模式下运行时,你用的是相同的chrome选项吗?我猜,其中一个正在阻止播放机(正如最后一个日志所说,
“Uncaught(in promise)HarmonyError:无法执行命令;本地播放机被禁用。”
)您可以安全地忽略
SameSite
警告,它们应该与此问题无关。@Jonah即使没有它们,也无法工作,我猜spotify不允许无头浏览器