|
5 | 5 | from selenium import webdriver |
6 | 6 | from selenium.webdriver.chrome.service import Service |
7 | 7 | from webdriver_manager.chrome import ChromeDriverManager |
| 8 | +import os,sys,shutil |
8 | 9 |
|
9 | | -def scrape_oliveyoung_products(max_items=10): |
| 10 | +def _build_chrome_driver(): |
10 | 11 | # Chrome config |
11 | | - chrome_options = webdriver.ChromeOptions() |
12 | | - chrome_options.add_argument("--headless") |
13 | | - chrome_options.add_argument("--no-sandbox") |
14 | | - chrome_options.add_argument("--disable-dev-shm-usage") |
15 | | - chrome_options.add_argument("--disable-gpu") |
16 | | - chrome_options.add_argument( |
17 | | - "user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36" |
| 12 | + options = webdriver.ChromeOptions() |
| 13 | + options.add_argument("--headless=new") |
| 14 | + options.add_argument("--no-sandbox") |
| 15 | + options.add_argument("--disable-dev-shm-usage") |
| 16 | + options.add_argument("--disable-gpu") |
| 17 | + options.add_argument( |
| 18 | + "user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 " |
| 19 | + "(KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36" |
18 | 20 | ) |
19 | 21 |
|
20 | | - # Browser 시작 |
21 | | - driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=chrome_options) |
| 22 | + # Linux (Ubuntu) 배포 서버 |
| 23 | + if sys.platform.startswith("linux"): |
| 24 | + # Prefer system chromium/chromedriver if they exist |
| 25 | + chromium_bin = shutil.which("chromium-browser") or shutil.which("chromium") |
| 26 | + chromedriver_sys = shutil.which("chromedriver") |
| 27 | + if chromium_bin and chromedriver_sys: |
| 28 | + options.binary_location = chromium_bin |
| 29 | + return webdriver.Chrome(service=Service(chromedriver_sys), options=options) |
| 30 | + |
| 31 | + # macOS/Windows or fallback -> use webdriver_manager |
| 32 | + return webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options) |
| 33 | + |
| 34 | +def scrape_oliveyoung_products(max_items=10): |
| 35 | + driver = _build_chrome_driver() |
22 | 36 | products = [] |
23 | 37 |
|
24 | 38 | try: |
|
0 commit comments