Search

[python, ์…€๋ ˆ๋‹ˆ์›€] ์šฐ๋ถ„ํˆฌ์—์„œ ChromeDriver ์‹คํ–‰ ์—๋Ÿฌ

ํƒ€์ž…
ํŠธ๋Ÿฌ๋ธ”์ŠˆํŒ…
ํƒœ๊ทธ
python
selenium
์ƒํƒœ
Published
์ƒ์„ฑ์ผ
2022/12/22 05:16
์ตœ์ข… ํŽธ์ง‘ ์ผ์‹œ
2023/02/24 11:36
2 more properties

๊ฐœ๋ฐœ ํ™˜๊ฒฝ

Ubuntu 22.04.1 LTS

์—๋Ÿฌ ์ƒํ™ฉ

ubuntu ํ™˜๊ฒฝ์—์„œ ์…€๋ ˆ๋‹ˆ์›€์„ ์‚ฌ์šฉํ•˜๋ ค๊ณ  ํ•จ.
chrome ์„ ์ •์ƒ์ ์œผ๋กœ ๋‹ค์šด๋ฐ›์•˜์ง€๋งŒ chrome-driver ๊ฐ€ ์ •์ƒ์ ์œผ๋กœ ์‹คํ–‰์ด ์•ˆ ๋จ
chrome ์€ /usr/bin/google-chrome ๊ฒฝ๋กœ์— ์ •์ƒ์ ์œผ๋กœ ๋‹ค์šด๋ฐ›์•„์ง„ ๋ชจ์Šต
chrome-driver ๋Š” ์ง์ ‘ ์„ค์น˜ํ•˜์ง€ ์•Š๊ณ  ChromeDriverManager ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋กœ ๊ทธ๋•Œ๊ทธ๋•Œ๋งˆ๋‹ค install ํ•˜๋„๋ก ํ–ˆ๋‹ค.
from webdriver_manager.chrome import ChromeDriverManager driver = webdriver.Chrome( service=Service(ChromeDriverManager().install()), options=options)
Python
๋ณต์‚ฌ

์—๋Ÿฌ ๋ฌธ๊ตฌ

The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.

์—๋Ÿฌ ํ•ด๊ฒฐ

ChromeDriverManager ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š๊ณ , chrome ๋ฒ„์ „์— ๋งž๋Š” chrome driver ๋ฅผ ์ง์ ‘ ์„ค์น˜ํ•ด์„œ ๊ฒฝ๋กœ๋ฅผ ์ž…๋ ฅํ•ด์ฃผ๋‹ˆ ํ•ด๊ฒฐ๋˜์—ˆ๋‹ค.
(mac ํ™˜๊ฒฝ์—์„œ๋Š” ChromeDriverManager ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋กœ๋„ ์ž˜ ๋๋Š”๋ฐ ubuntu ์—์„œ๋Š” ์™œ ์•ˆ ๋˜๋Š”์ง€๋Š” ์ž˜ ๋ชจ๋ฅด๊ฒ ๋‹ค,,)
์•„๋ž˜ ๋ธ”๋กœ๊ทธ์— ๋‚˜ํ•˜๊ณ  ๋˜‘๊ฐ™์€ ์ƒํ™ฉ (mac ์€ ์ž˜ ๋˜๋Š”๋ฐ, ubuntu ์—์„œ ์•ˆ ๋จ) ์ธ ๋ถ„์ด ์˜ฌ๋ ค์ฃผ์‹  ํฌ์ŠคํŒ…์„ ์ฐธ๊ณ ํ–ˆ๋‹ค!

์ถ”๊ฐ€) chrome ๋ถ€ํ„ฐ chrome driver ์„ค์น˜ & ์‚ฌ์šฉ ๋ฐฉ๋ฒ•

chrome ์„ค์น˜

wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
Shell
๋ณต์‚ฌ
sudo sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list'
Shell
๋ณต์‚ฌ
sudo apt-get update
Shell
๋ณต์‚ฌ
sudo apt-get install google-chrome-stable
Shell
๋ณต์‚ฌ
ํฌ๋กฌ ๋ฒ„์ „ ํ™•์ธ
google-chrome --version
Shell
๋ณต์‚ฌ

chrome driver ์„ค์น˜

์œ„์—์„œ ์„ค์น˜ํ•œ ํฌ๋กฌ์˜ ๋ฒ„์ „์— ๋งž๋Š” chrome driver ๋ฅผ ์„ค์น˜ํ•ด์ค˜์•ผ ํ•œ๋‹ค.
์›ํ•˜๋Š” ๋ฒ„์ „์— ๋“ค์–ด๊ฐ€์„œ linux64.zip ์˜ ๋‹ค์šด๋กœ๋“œ ๋งํฌ๋ฅผ ๋ณต์‚ฌํ•œ๋‹ค.
wget ์œผ๋กœ ๋‹ค์šด๋กœ๋“œ
wget -N https://chromedriver.storage.googleapis.com/84.0.4147.30/chromedriver_linux64.zip
Shell
๋ณต์‚ฌ
unzip ์œผ๋กœ ์••์ถ•ํ•ด์ œ
unzip chromedriver_linux64.zip
Shell
๋ณต์‚ฌ

์ฝ”๋“œ ์ ์šฉ

from bs4 import BeautifulSoup from selenium import webdriver from selenium.webdriver.chrome.service import Service from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.support.wait import WebDriverWait from webdriver_manager.chrome import ChromeDriverManager from selenium.webdriver.common.keys import Keys options = webdriver.ChromeOptions() options.add_argument("--headless") options.add_argument("--no-sandbox") options.add_argument("--disable-dev-shm-usage") options.add_argument("window-size=1920x1080") options.add_argument( "user-agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36" ) options.add_argument("lang=ko_KR") driver = webdriver.Chrome( executable_path='ํฌ๋กฌ๋“œ๋ผ์ด๋ฒ„ ์„ค์น˜๊ฒฝ๋กœ', options=options )
Shell
๋ณต์‚ฌ