Dev.YoungKyu
YoungKyu's Devlog
전체 방문자
오늘
어제
  • 분류 전체보기 N
    • 부스트캠프
    • iOS N
    • visionOS
    • Backend
    • 알고리즘
    • CS
    • Git
    • Python
    • 끄적끄적

블로그 메뉴

  • 홈
  • 🌝 티스토리 홈
  • ⭐️ 깃허브
  • 태그

공지사항

인기 글

최근 댓글

최근 글

태그

  • Python
  • 티스토리챌린지
  • jekyll
  • Swift5.7
  • swift
  • 소프트웨어 공학
  • CS
  • Optional
  • guard
  • AVAudioSession
  • 소프트웨어공학
  • Concurrency
  • boj
  • authenticationinterceptor
  • MVC
  • constraint
  • if let
  • 모듈화
  • Git
  • 오블완
  • ios
  • ImageResource
  • alamofire
  • 알고리즘
  • 소프트웨어 테스트
  • image
  • 백준
  • AutoLayout
  • 부스트캠프
  • SwiftUI

티스토리

hELLO · Designed By 정상우.
Dev.YoungKyu
Python Selenium Webdriver Chrome Option 관련 오류
Python

Python Selenium Webdriver Chrome Option 관련 오류

2023. 6. 8. 19:41

ChromeDriver를 활용해 크롤링을 구현해놨는데 오늘 처음보는 에러가 나왔다.

내용을 읽어보니 chrome_options 라는 argument 가 안맞는 듯 해 혹시하고 Selenium 공식 사이트를 확인해 보았다.

get_upcoming_items...
__init__() got an unexpected keyword argument 'chrome_options'
finally...
Traceback (most recent call last):
  File "/home/runner/work/ShoesPlease/ShoesPlease/parser/get_upcoming_items.py", line 23, in get_upcoming_items
    driver = webdriver.Chrome('chromedriver', chrome_options=options)
TypeError: __init__() got an unexpected keyword argument 'chrome_options'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/runner/work/ShoesPlease/ShoesPlease/parser/get_upcoming_items.py", line 57, in get_upcoming_items
    driver.quit()
UnboundLocalError: local variable 'driver' referenced before assignment

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "run.py", line 8, in <module>
    upcoming_items = get_upcoming_items()  # upcoming 탭의 모든 아이템
  File "/home/runner/work/ShoesPlease/ShoesPlease/parser/get_upcoming_items.py", line 61, in get_upcoming_items
    driver.quit()
UnboundLocalError: local variable 'driver' referenced before assignment
Error: Process completed with exit code 1.

원인

https://www.selenium.dev/blog/2023/selenium-4-10-0-released/

 

Selenium 4.10.0 Released!

Today we're happy to announce that Selenium 4.10.0 has been released!

www.selenium.dev

selenium이 23.06.07 일자로 4.10.0 으로 업데이트가 되었다.

몇몇 클래스의 인자가 변경되었는데, 그 중에 webdriver.Chrome() 의 인자 중 'chrome_options' 가 'options' 로 변경된게 문제였다.

 

대응

from selenium import webdriver
from selenium.webdriver.chrome.service import Service as ChromeService
from selenium.webdriver.chrome.options import Options as ChromeOptions
from webdriver_manager.chrome import ChromeDriverManager

options = ChromeOptions()
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"
options.add_argument('user-agent=' + user_agent)
options.add_argument("lang=ko_KR")
options.add_argument('headless')
options.add_argument('window-size=1920x1080')
options.add_argument("disable-gpu")
options.add_argument("--no-sandbox")
        
# 크롬 드라이버 최신 버전 설정
service = ChromeService(executable_path=ChromeDriverManager().install())
        
# chrome driver
driver = webdriver.Chrome(service=service, options=options) # <- options로 변경
저작자표시 (새창열림)
    Dev.YoungKyu
    Dev.YoungKyu
    iOS를 공부하고 있습니다

    티스토리툴바