이 문제에 대한 너무 오래 파고 후, 드디어 해결책을 찾았습니다. GUI없이 우분투가 나오면 엉덩이를 다룰 고통이 있습니다. Selenium Webdriver를 시작하려고 할 때. 일반 webdriver.Chrome뿐만 아니라 webdriver.Remote 몇 가지 옵션을 추가해야합니다.
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import
DesiredCapabilities
options = webdriver.ChromeOptions()
options.binary_location = '/usr/bin/google-chrome'
options.add_argument('headless')
options.add_argument('--no-sandbox')
driver = webdriver.Chrome(chrome_options=options)
executor_url = driver.command_executor._url
session_id = driver.session_id
driver.get("http://www.google.com")
print(session_id)
print(executor_url)
print(driver.current_url)
driver2 = webdriver.Remote(command_executor=executor_url, desired_capabilities=options.to_capabilities())
driver2.close()
driver2.session_id = session_id
print(driver2.current_url)
driver2.get("http://www.facebook.com")
print(driver2.current_url)
또한 webdriver.remote를 사용하면 좀비 웹 드라이버도 열립니다. 기존 webdriver에 다시 첨부하는 경우에만 신경 써야합니다. 새 드라이버를 이전 드라이버에 연결하기 전에 새 드라이버를 닫을 수 있습니다.
기본 우분투 설치에는 윈도우 시스템이 설치되어 있지 않습니다. 윈도 잉 시스템과 크롬을 설치 했습니까? – stdunbar
@stdunbar AWS EC2 인스턴스이므로 GUI가 없습니다. 터미널을 통해 코드를 실행하고 헤드가없는 웹 드라이버를 설정했습니다. 윈도우 시스템 설치가 도움이되는지 확실하지 않습니다. – SwagZ
GUI가 없으면 Chrome을 실행할 수 없습니다. 헤드리스는 모니터가 연결되어 있지 않다는 것을 의미합니다. – stdunbar