python 3.8
selenium 4.1.3
--disable-dev-shm-usage
옵션도 추가해준다.Message: unknown error: session deleted because of page crash
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
def set_chrome_driver():
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
chrome_options.add_argument('--lang=ko_KR')
chrome_options.add_argument("--disable-gpu")
chrome_options.add_argument('--window-size=1920x1080')
# headless임을 숨기기 위해서
# headless인 경우 Cloudflare 서비스가 동작한다.
chrome_options.add_argument(
"user-agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36")
driver = webdriver.Chrome(service=Service(
ChromeDriverManager().install()), options=chrome_options)
return driver
if __name__ == "__main__":
driver = set_chrome_driver()
url = 'https://namu.wiki/w/%EA%B8%B0%EC%B4%88%EC%83%9D%ED%99%9C%EB%B3%B4%EC%9E%A5%EC%A0%9C%EB%8F%84'
driver.get(url=url)
print(driver.title)
html = driver.page_source
print(html)
driver.close()
배우고 갑니다. 감사합니다.