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

블로그 메뉴

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

공지사항

인기 글

최근 댓글

최근 글

태그

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

티스토리

hELLO · Designed By 정상우.
Dev.YoungKyu
Python

Python Selenium Webdriver Chrome Option 관련 오류

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를 공부하고 있습니다

티스토리툴바

단축키

내 블로그

내 블로그 - 관리자 홈 전환
Q
Q
새 글 쓰기
W
W

블로그 게시글

글 수정 (권한 있는 경우)
E
E
댓글 영역으로 이동
C
C

모든 영역

이 페이지의 URL 복사
S
S
맨 위로 이동
T
T
티스토리 홈 이동
H
H
단축키 안내
Shift + /
⇧ + /

* 단축키는 한글/영문 대소문자로 이용 가능하며, 티스토리 기본 도메인에서만 동작합니다.