ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 파이썬 Selenium을 이용하여 요일별 웹툰 목록 출력하기
    파이썬 2020. 10. 9. 18:21

    실행 화면

    소스

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    from selenium import webdriver
    from webdriver_manager.chrome import ChromeDriverManager  # 'webdriver_manager' 패키지모듈 다운로드 필요
    from selenium.webdriver.chrome.options import Options
     
    if __name__ == '__main__':  # 파이썬 프로그램 시작점
     
        # 브라우저 자동화 작업을 화면에 표시하지 않게 됨
        options = Options()
        options.headless = True
     
        # 웹드라이버 객체 선언 및 웹드라이버를 최신 버전으로 설치
        driver = webdriver.Chrome(executable_path=ChromeDriverManager().install(), options=options)
        print('1. 월요일')
        print('2. 화요일')
        print('3. 수요일')
        print('4. 목요일')
        print('5. 금요일')
        print('6. 토요일')
        print('7. 일요일')
        day_of_the_week = input("웹툰 목록을 출력할 요일을 입력해주세요: ")
     
        # 브라우저 주소에 해당 하는 페이지를 불러온다.
        driver.get('https://comic.naver.com/webtoon/weekday.nhn');
     
        # xpath 경로를 입력하여 웹툰 목록을 불러온다.
        webtoon_list = driver.find_elements_by_xpath(
                            "//body/div[@id='wrap']/div[@id='container']/div[@id='content']"
                            "/div[@class='list_area daily_all']/div[{}]/div/ul/li/a"
                            .format(day_of_the_week))
        
        # 웹툰 목록을 전부 출력
        for webtoon_name in webtoon_list:
            print(webtoon_name.text)
     
    cs

     

    댓글

Designed by Tistory.