在我的Ubuntu服务器20.04上,我安装了Python,Selenium,Chrome,Chromedriver,当我试图运行我的脚本时,我得到了一些错误
这是Python程序:
# Import request lib
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
import time #for calculate time of process
import datetime # for actual time and report of time of update
import random
# Read file with login and pass
start_time = time.time() #time of start function
update_resumes = 0 # amount of updated resume
service = Service(executable_path=r'/usr/bin/chromedriver/chromedriver') #/absolute/path/to/chromedriver
options = Options() #webdriver.ChromeOptions()
options.add_argument('--headless')
#driver = webdriver.Chrome(service=service, options=options)
#options = Options()
#options.add_argument('--headless')
browser = webdriver.Chrome(service=service, options=options)
try:
with open("/home/demo/hh-auto-raise-resume-server/hh-auto-raise-resume-server/login_pass_real.txt",
"r") as f: # Change to correct file in GitGub. Open the files file in the same directory as the file and open it in the r variable
lines = f.readlines() # read the file line by line into a variable
user_name = lines[0].rstrip('\n') # Remove the line break from the first line
password = lines[1]
# print(user_name) # control correct value
# print(password) # control correct value
link = "https://sitename . xxx/"
#browser = webdriver.Chrome(service=service, options=options)
browser.get(link)
# Tap button "Entry"
delay = random.randint(1, 10)
element1 = WebDriverWait(browser, delay).until(EC.presence_of_element_located((By.CSS_SELECTOR, 'correct_selector')))
button = browser.find_element(By.CSS_SELECTOR, 'correct_selector"]')
button.click()
##time.sleep(delay)
#other part of code
finally:
browser.quit()
#some other code without work with Chrome and Chrome driver
字符串
我通过运行以下命令启动它:
python3 /home/demo/hh-auto-raise-resume-server/hh-auto-raise-resume-server/main.py
型
这是错误日志:
root@vmSERVER_NAME:~# python3 /home/demo/hh-auto-raise-resume-server/hh-auto-raise-resume-server/main.py
Traceback (most recent call last):
File "/home/demo/hh-auto-raise-resume-server/hh-auto-raise-resume-server/main.py", line 26, in <module>
browser = webdriver.Chrome(service=service, options=options)
File "/usr/local/lib/python3.8/dist-packages/selenium/webdriver/chrome/webdriver.py", line 45, in __init__
super().__init__(
File "/usr/local/lib/python3.8/dist-packages/selenium/webdriver/chromium/webdriver.py", line 56, in __init__
super().__init__(
File "/usr/local/lib/python3.8/dist-packages/selenium/webdriver/remote/webdriver.py", line 205, in __init__
self.start_session(capabilities)
File "/usr/local/lib/python3.8/dist-packages/selenium/webdriver/remote/webdriver.py", line 289, in start_session
response = self.execute(Command.NEW_SESSION, caps)["value"]
File "/usr/local/lib/python3.8/dist-packages/selenium/webdriver/remote/webdriver.py", line 344, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python3.8/dist-packages/selenium/webdriver/remote/errorhandler.py", line 229, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: session not created: Chrome failed to start: exited normally.
(session not created: DevToolsActivePort file doesn't exist)
(The process started from chrome location /opt/google/chrome/chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
Stacktrace:
#0 0x55a9936f8fb3 <unknown>
#1 0x55a9933cc4a7 <unknown>
#2 0x55a9933ffc93 <unknown>
#3 0x55a9933fc10c <unknown>
#4 0x55a99343eac6 <unknown>
#5 0x55a993435713 <unknown>
#6 0x55a99340818b <unknown>
#7 0x55a993408f7e <unknown>
#8 0x55a9936be8d8 <unknown>
#9 0x55a9936c2800 <unknown>
#10 0x55a9936cccfc <unknown>
#11 0x55a9936c3418 <unknown>
#12 0x55a99369042f <unknown>
#13 0x55a9936e74e8 <unknown>
#14 0x55a9936e76b4 <unknown>
#15 0x55a9936f8143 <unknown>
#16 0x7f95c34c4609 start_thread
型
Google Chrome和Chrome驱动程序的版本相同:
root@vmSERVER_NAME:~# google-chrome --version
Google Chrome 118.0.5993.70
root@vmSERVER_NAME:~# /usr/bin/chromedriver/chromedriver --version
ChromeDriver 118.0.5993.70 (e52f33f30b91b4ddfad649acddc39ab570473b86-refs/branch-heads/5993@{#1216})
型
我不知道该怎么办。我需要帮助。
1条答案
按热度按时间eblbsuwk1#
这段代码修复了问题。我把它加在关于
字符串
代码
型