강의

멘토링

커뮤니티

Cộng đồng Hỏi & Đáp của Inflearn

Hình ảnh hồ sơ của getup90828
getup90828

câu hỏi đã được viết

Python cơ bản và tạo nhiều ứng dụng tự động hóa khác nhau bằng cách sử dụng web crawling

Thực hành Scraping và Parsing không dùng Trình duyệt Web (2) - Tự động hóa Naver Cafe

네이버 로그인 질문이요

Viết

·

298

0

인터넷으로 찾아보니까 클립보드를 이용하는 방법이 있어서 해보았습니다. 네이버에서 로그인 까지는 성공하는데

    self.driver.get('https://cafe.naver.com/AttendanceView.nhn?search.clubid=18824112&search.menuid=98')

여기서 부터는 실행이 안되버리네요 이유를 모르겠네요

import sys

import io

from selenium import webdriver

from selenium.webdriver.common.keys import Keys

from selenium.webdriver.chrome.options import Options

import time

import pyperclip

 

sys.stdout = io.TextIOWrapper(sys.stdout.detach(), encoding = 'utf-8')

sys.stderr = io.TextIOWrapper(sys.stderr.detach(), encoding = 'utf-8')

 

#chrome_options = Options()

#chrome_options.add_argument("--headless") #CLI

 

class NcafeWriteAtt:

    #초기화 실행(webdriver 설정)

    def __init__(self):

        #chrome_options = Options()

        #chrome_options.add_argument("--headless") #CLI

        #self.driver = webdriver.Chrome(chrome_options=chrome_options, executable_path="C:/pythonworkspaace/test_src/section3/webdriver/chrome/chromedriver")

        self.driver = webdriver.Chrome('C:/pythonworkspaace/test_src/section3/webdriver/chrome/chromedriver')

        self.driver.set_window_size(1920, 1280)

        self.driver.implicitly_wait(5)

 

    #네이버 카페 로그인 && 출석 체크

    def writeAttendCheck(self):

        self.driver.get('https://www.naver.com')

        login_btn = self.driver.find_element_by_class_name('ico_local_login')

        login_btn.click()

        time.sleep(1)

 

        tag_id = self.driver.find_element_by_name('id')

        tag_pw = self.driver.find_element_by_name('pw')

        tag_id.clear()

        time.sleep(1)

 

        tag_id.click()

        pyperclip.copy('아이디')

        tag_id.send_keys(Keys.CONTROL, 'v')

        time.sleep(1)

 

        tag_pw.click()

        pyperclip.copy('비밀번호')

        tag_pw.send_keys(Keys.CONTROL, 'v')

        time.sleep(1)

 

        login_btn = self.driver.find_element_by_id('log.login')

        login_btn.click()

 

        #self.driver.implicitly_wait(1)

        self.driver.get('https://cafe.naver.com/AttendanceView.nhn?search.clubid=18824112&search.menuid=98')

        self.driver.implicitly_wait(30)

        self.driver.switch_to_frame('cafe_main')

        self.driver.find_element_by_id('cmtinput').send_keys('반갑습니다!!.')

        self.driver.find_element_by_xpath('//*[@id="btn-submit-attendance"]').click()

        time.sleep(10)

 

        #소멸자

        def __del__(self):

            #self.driver.close() #현재 실행 포커스 된 영역을 종료

            self.driver.quit() #Seleninum 전체 프로그램 종료

            print("Removed driver Object")

 

#실행

if __name__ == '__main__':

    #객체 생성

    a = NcafeWriteAtt()

    #시작

    start_time = time.time()

    #프로그램 실행

    a.writeAttendCheck()

    #종료시간 출력

    print("--Total %s seconds --" % (time.time() - start_time))

    #객체 소멸

    del a

python웹-크롤링

Câu trả lời 2

1

niceman님의 프로필 이미지
niceman
Người chia sẻ kiến thức

안녕하세요.

현재 selenium 로그나 기타 메세지 없이 디버깅을 하는것은 쉽지 않네요 ㅠ

후에 소스코드 실행해보고 예제를 수정해서 올려드리겠습니다.

감사합니다.

0

getup90828님의 프로필 이미지
getup90828
Người đặt câu hỏi

저 소스 중  id / pw 붙여넣기 > 로그인 버튼 클릭. 이 다음에 sleep 이랑 강사님이 말씀하신 명시적인 wait 10 정도 주니까 정상 으로 출석 게시판에 글을 쓰는걸 확인 했습니다.

Hình ảnh hồ sơ của getup90828
getup90828

câu hỏi đã được viết

Đặt câu hỏi