inflearn logo
강의

講義

知識共有

Python 入門と Web クロールの活用によるさまざまな自動化アプリケーションの作成

ウェブブラウザなしで スクレイピングとパース 実践(2) - 네이버 카페 자동화

네이버자동로그인_by_selenium

876

Seung Park

投稿した質問数 8

0

안녕하세요 네이버자동로그인 실습중에

셀레니움문법변경및 기타수정사항반영하여 아래처럼코드를 완성시켰습니다 2022_07_27 현재 headless없이 하면 잘됩니다

그런데 options에 headless를 주고하면 로그인이 안됩니다 사이트마다 headless막는 경우 user-agent설정을 해주면 된다고 하셨는데 그래도 안되네요 로그인한 후 아래 화면이 떠야 하는데 headless모드에서는 아래화면이 안뜨고 바로 capcha화면으로 넘어가더라구요 방법이 없을까요??

전체코드는 아래와같습니다

 
import sys
import io
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import time
import pyperclip
from selenium.webdriver.common.keys import Keys
from fake_useragent import UserAgent
user_id = 'xx'
user_pw = 'xx'
ua = UserAgent()
print(ua.chrome)

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

class NcafeWriteAtt:
    #초기화 실행(webdriver 설정)
    def __init__(self):
        chrome_options = Options()
        chrome_options.add_argument('--headless')
        chrome_options.add_argument("disable-gpu")
        chrome_options.add_argument("user-agent="+ua.chrome)
        self.driver = webdriver.Chrome(options=chrome_options)
        self.driver.implicitly_wait(5)

    #네이버 카페 로그인 && 출석 체크
    def writeAttendCheck(self):
        self.driver.get('https://nid.naver.com/nidlogin.login')
        pyperclip.copy(user_id)
        self.driver.find_element('xpath','//*[@id="id"]').send_keys(Keys.CONTROL, 'v')
        self.driver.implicitly_wait(3)
        pyperclip.copy(user_pw)
        self.driver.find_element('xpath','//*[@id="pw"]').send_keys(Keys.CONTROL, 'v')
        self.driver.implicitly_wait(3)
        self.driver.find_element('xpath','//*[@id="log.login"]/span').click()
        self.driver.implicitly_wait(3)      
        print("로그인 완료")
        self.driver.implicitly_wait(3)
        self.driver.get('https://cafe.naver.com/AttendanceView.nhn?search.clubid=12730407&search.menuid=99&search.attendyear=2022&search.attendmonth=07&search.attendday=27&search.page=1&lcs=Y')
        self.driver.implicitly_wait(3)
        self.driver.switch_to.frame('cafe_main')
        self.driver.implicitly_wait(3)
        self.driver.find_element('xpath','//*[@id="cmtinput"]').send_keys('출석')
        self.driver.implicitly_wait(3)
        self.driver.find_element('xpath','//*[@id="btn-submit-attendance"]').click()
        time.sleep(1)

    # 소멸자
    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

回答 1

2

niceman

네 현재는 headless 파라미터가 인식되면 로그인이 안되는 것으로 보여요

서버 자체에서 로그인 리젝을 하기 때문에요!

현재 예제에서 error 발생

0

367

3

유튜브 동영상 다운로드

0

1448

2

Atom 에디터 관련

0

337

1

위시켓 폼데이터

0

274

1

스케줄러 사용 관련 질문 드립니다

0

627

1

selenium 에러

0

428

1

Progress bar 쓰레드 관련

0

489

1

Install Package 관련 문의

0

328

1

tkinter 샘플 코드 실행 오류 건

0

1267

1

4-7-6 네이버 & 카카오 주식 정보 가져오기

0

381

1

위시캣 로그인 처리 및 크롤링 질문

0

344

1

2-8-1 네이버이미지 크롤링 질문

1

604

3

li:nth-of-type 질문

0

350

2

에러가 뜨는데 잘 모르겠어요ㅠ

0

401

2

Install Packages 항목이 안보이는 이유가 뭘까요?

0

400

2

환경변수 Path 설정 방법

0

631

1

웹 브라우저 없는 스크랩핑 및 파싱 실습(1) - 인프런

0

333

1

웹 브라우저 없는 스크랩핑 및 파싱 실습(1) -git주소

0

475

3

download2-8-1. py질문

0

203

1

ip 차단 당하는 거 같은데 아무리 랜덤주고, sleep 줘도 안 되는데 다른 방법 더 있을까요??

0

645

1

인프런 환경이 바뀌어서 제나름대로 하는데

0

196

1

다시올려주신 예제파일로하는데

0

190

1

아직도 에러가뜨나보네요?

0

584

1

강의버전 업데이트좀 해주세요...

0

173

1