728x90

오랫만에 크롤링을 해보려고 하니까 selenium 드라이브 설치없이 auto 로 설정하는 옵션이 전혀 동작하지 않는다.

버전업이 중단되어서 동작이 안되는가 보다.

방식이 새롭게 변경되었다는 걸 검색하고 테스트 해본 결과 확인했다.

 

아래 코드를 CentOS 7 에서 실행해보니 안된다. Windows10 환경에서는 잘 된다.

CentOS 7 환경에서 성공한 사항은 다음 게시글에 기록해둔다.

# pip install -U selenium  # Selenium is upgraded to v4.0.0
# pip install webdriver-manager  # Webdriver Manager for Python is installed
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
 
import time
 
def jusoGet(keyword):
    # 크롬 드라이버 생성
    options = Options()
    #options.add_experimental_option("detach", False) # 브라우저 창 떳다기 사라지기(False), 계속 유지(True)
    options.add_argument("headless"# 창 숨기는 옵션
    driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)
    # driver.maximize_window() # 브라우저 창 최대로 하는 옵션인데 필요없을 거 같다.
 
    # 페이지 로딩이 완료될 때 까지 기다리는 코드
    driver.implicitly_wait(1)
 
    # 사이트 접속하기
    url = 'https://www.juso.go.kr/support/AddressMainSearch.do?searchKeyword='
    driver.get(url+keyword) # url 페이지로 이동
    time.sleep(2# 로딩 대기
 
    try:
        h = driver.find_element(By.XPATH, value='//*[@id="list1"]/div[2]/span[2]').text
        print(h)
    except:
        pass
 
 
if __name__ == "__main__":
    keyword = '서초구청'
    jusoGet(keyword)

 

 

 

크롬 브라저에 맞는 driver 설치방법 → 불필요

드라이버 설치하고 해보면 아래와 같은 경고 문구가 나온다.

DeprecationWarning: executable_path has been deprecated, please pass in a Service object

 

아래 내용은 불필요한 사항이지만 나중에 보면서 이런 적도 있었구나 하는 셈치고 적어둔다.

chrome://settings/help 를 크롬 브라우저에서 실행하여 현재 버전을 찾아야 한다.

 

 

https://chromedriver.chromium.org/downloads/version-selection

 

ChromeDriver - WebDriver for Chrome - Version Selection

Version selection is the process of matching a Chrome binary of a given version to a compatible ChromeDriver binary. For versions 115 and newer Starting with M115 the ChromeDriver release process is integrated with that of Chrome. The latest Chrome + Chrom

chromedriver.chromium.org

사이트에 접속하면 최신버전과 맞지 않는다.

 

더 최신버전을 위에서 찾아들어가야 한다.

https://googlechromelabs.github.io/chrome-for-testing/

 

Chrome for Testing availability

chrome-headless-shellmac-arm64https://storage.googleapis.com/chrome-for-testing-public/123.0.6312.58/mac-arm64/chrome-headless-shell-mac-arm64.zip200

googlechromelabs.github.io

 

 

블로그 이미지

Link2Me

,