硒铬坠毁

时间:2020-05-25 12:32:11

标签: python python-3.x selenium

m trying to run this code that runs fine on my windows machine on a ubuntu server, but I在这里遇到此错误

 selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: crashed.
  (unknown error: DevToolsActivePort file doesn't exist)
  (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)

这是我要在ubuntu服务器上运行的代码,它可以在Windows计算机上正常运行(是的,我更换了chromedriver),有人知道如何解决吗?尝试了Internet上的每个配置,但无济于事!

from selenium import webdriver
import time
from selenium.webdriver.chrome.options import Options
from RC import RC
class youtube_bot():

def __init__(self):
    self.options = Options()
    self.options.add_experimental_option("detach", True)

    PROXY = "163.172.221.119:19002"
    self.options.add_argument("--no-sandbox");
    self.options.add_argument('--proxy-server=%s' % PROXY)
    self.options.add_argument('--disable-dev-shm-usage')



    webdriver.DesiredCapabilities.CHROME['proxy'] = {
        "httpProxy": PROXY,
        "ftpProxy": PROXY,
        "sslProxy": PROXY,
        "noProxy": None,
        "proxyType": "MANUAL",
        "autodetect": False
    }
    self.driver = webdriver.Chrome(executable_path=RC.chromedriver_path, options=self.options)
    self.driver.get(RC.youtube_link)


def open_youtube_video(self):

    time.sleep(30)
    #paste youtube inside of self.driver.get
    try:
        self.driver.find_element_by_xpath('/html/body/ytd-app/div/ytd-page-manager/ytd-watch-flexy/div[4]/div[1]/div/div[1]/div/div/div/ytd-player/div/div/div[4]/button').click()
        print('Video running')
    except:
        pass
    time.sleep(2)
    print("Video is playing")
    self.driver.refresh()

def close_youtube_video(self):
    self.driver.refresh()


while True:

    a = youtube_bot()
    a.open_youtube_video()
    time.sleep(30)
    print("Ran 1 time")
    a.close_youtube_video()
    time.sleep(30)
    print("It ran 1 more time successfully")

0 个答案:

没有答案