ํ‹ฐ์Šคํ† ๋ฆฌ ๋ทฐ

728x90
๋ฐ˜์‘ํ˜•
์˜ค๋žœ๋งŒ์— ์…€๋ ˆ๋‹ˆ์›€์„ ํ™œ์šฉํ•  ์ผ์ด ์žˆ์–ด ๊ธฐ์กด์ฒ˜๋Ÿผ, ํฌ๋กฌ ๋“œ๋ผ์ด๋ฒ„๋ฅผ ๋กœ์ปฌ์— ์ง์ ‘ ๋‹ค์šด๋กœ๋“œํ•˜์—ฌ ์‚ฌ์šฉํ•˜์˜€๋‹ค. ๊ทธ๋Ÿฐ๋ฐ ์ž‘์„ฑํ•œ ์ฝ”๋“œ๋ฅผ exe๋กœ ๋งŒ๋“ค์–ด ๋‹ค๋ฅธ ์‚ฌ๋žŒ์—๊ฒŒ ๋ฐฐํฌํ•  ์ผ์ด ์ƒ๊ฒผ๋‹ค. exe๋ฅผ ๋งŒ๋“ค๊ณ , ํฌ๋กฌ ๋“œ๋ผ์ด๋ฒ„ ๋ฒ„์ „์ด ๋‹ฌ๋ผ ๋‹ค๋ฅธ ํ™˜๊ฒฝ์—์„œ ์‹คํ–‰ ์‹œ ํ˜ธํ™˜๋˜์ง€ ์•Š๋Š” ๊ฒƒ์ด ์žˆ์–ด ์–ด๋–ป๊ฒŒ ํ•˜์ง€ ๊ณ ๋ฏผํ•˜๋ฉด์„œ ๊ฒ€์ƒ‰ํ•ด๋ณด๋‹ค๊ฐ€ ์ข‹์€ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๊ฐ€ ์žˆ์–ด์„œ ๋‹ค๋ค„๋ณด๊ณ ์ž ํ•œ๋‹ค.

 

webdriver_manager?

 

webdriver-manager

Library provides the way to automatically manage drivers for different browsers

pypi.org

 ํ˜ธ์ŠคํŠธ์— ์„ค์น˜ ๋œ `ํฌ๋กฌ`, `ํŒŒ์ด์–ดํญ์Šค`, `์˜คํŽ˜๋ผ` ๋“ฑ์„ ํ™œ์šฉํ•˜์—ฌ ๊ฐ ๋ธŒ๋ผ์šฐ์ € ๋ณ„ ๋“œ๋ผ์ด๋ฒ„๋ฅผ ๋‹ค์šด๋กœ๋“œํ•˜์ง€ ์•Š๋”๋ผ๋„ ๋‹ค์šด๋กœ๋“œํ•ด์„œ ํ”„๋กœ์ ํŠธ์— ํฌํ•จํ•œ ๊ฒƒ๊ณผ ๋™์ผํ•˜๊ฒŒ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ ํ™˜๊ฒฝ์„ ๋งŒ๋“ค์–ด ์ค€๋‹ค. ๊ธฐ๋ณธ์ ์ธ ์˜ˆ์‹œ๋Š” ์œ„ ์‚ฌ์ดํŠธ์—์„œ ์ฐธ๊ณ ํ•ด์„œ ๋ณผ ์ˆ˜ ์žˆ๋‹ค.

 

๊ฐ„๋‹จํ•œ ์˜ˆ์ œ

import os
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager

options = Options()
# VGA ๊ฐ€์†ํ™”๋ฅผ ๋”.
options.add_argument('disable-gpu')
# ๋ธŒ๋ผ์šฐ์ € ์ฐฝ์„ ์ˆจ๊น€.
options.add_argument('--headless')
# --headless ์ƒํƒœ์—์„œ, agent ์ •๋ณด๋ฅผ ํ‘œ๊ธฐํ•˜๊ธฐ ์œ„ํ•ด ํ•„์š”ํ•˜๋‹ค๊ณ  ํ•จ.
options.add_argument('user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Whale/3.12.129.46 Safari/537.36')
# ๋ถˆํ•„์š”ํ•œ ๋กœ๊ทธ๋ฅผ ์ถœ๋ ฅํ•˜์ง€ ์•Š๋„๋ก ํ•จ.
os.environ['WDM_LOG_LEVEL'] = '0'

# driverManager๋ฅผ ํ†ตํ•ด driver์ดˆ๊ธฐํ™”.
driver = webdriver.Chrome(options=options, service=Service(ChromeDriverManager().install()))

 ์œ„์™€ ๊ฐ™์ด ์ ์ ˆํ•œ ์˜ต์…˜์„ ์ค€ ํ›„์—, ์‹คํ–‰ํ•˜๋ฉด driver๊ฐ€ ์ •์ƒ์ ์œผ๋กœ ์ดˆ๊ธฐํ™” ๋˜๋Š” ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค. 

 

๋ถˆํ•„์š”ํ•œ ๋กœ๊ทธ ์ถœ๋ ฅ ์—†์• ๊ธฐ

====== WebDriver manager ======
Current google-chrome version is 96.0.4664
Get LATEST chromedriver version for 96.0.4664 google-chrome
Driver [C:\Users\test\.wdm\drivers\chromedriver\win32\96.0.4664.45\chromedriver.exe] found in cache

 `os.environ['WDM_LOG_LEVEL'] = '0'`์„ ๋„ฃ์ง€ ์•Š์œผ๋ฉด ์œ„์™€ ๊ฐ™์ด ๋ถˆํ•„์š”ํ•œ ๋กœ๊ทธ๊ฐ€ ์ถœ๋ ฅ๋œ๋‹ค. ์ด๋ฅผ ์ถœ๋ ฅํ•˜์ง€ ์•Š๊ธฐ ์œ„ํ•ด ์—ฌ๋Ÿฌ ๊ณณ์„ ๊ฒ€์ƒ‰ํ•˜๋‹ค๊ฐ€, webdriver ์ž์ฒด์˜ ์˜ต์…˜์ด ์•„๋‹Œ, os์˜ ๋กœ๊ทธ ๋ ˆ๋ฒจ์„ ์„ค์ •ํ•˜๋‹ˆ ํ•ด๊ฒฐ๋˜์—ˆ๋‹ค.๐Ÿ˜€

728x90
๋ฐ˜์‘ํ˜•
๋Œ“๊ธ€
๊ธ€ ๋ณด๊ด€ํ•จ
์ตœ๊ทผ์— ์˜ฌ๋ผ์˜จ ๊ธ€
์ตœ๊ทผ์— ๋‹ฌ๋ฆฐ ๋Œ“๊ธ€