본문 바로가기
IT/프로그래밍

파이썬 네이버 로그인 에러 - 내 일을 바꾸는 업무 자동화 14장

by nutrient 2021. 5. 29.
728x90
728x170

 

 

debug_1.py

int('string')

 

debug_2.py

from my_error import raise_error
raise_error()

 

error_1.py

data = 10
if data > 0:
    print('ok')
	print('error')

 

error_2.py

data = 10
if data > 0:
    print('ok')
     print('error')

 

error_3.py

data = 10
if data > 0:
    print('ok')
    
    if data > 5:
        print('ok2')
     print('error')

 

error_4.py

value = 100
print(vaiue)

 

error_5.py

from selenium import webdriver

driver = webdriver.Chrome('./chromedriver')

try:
    driver.get('http://naver.com')

    elem = driver.find_element_by_class_name('query')

except Exception as e:
    print(e)
finally:
    driver.quit()

 

error_6.py

from selenium import webdriver

driver = webdriver.Chrome('./chromedriver')

try:
    driver.get('http://news.naver.com')

    elem = driver.find_elements_by_id('right.ranking_contents')

    news_list = elem.find_elements_by_tag_name('li')
    for news in news_list:
        print(news.text)

except Exception as e:
    print(e)
finally:
    driver.quit()

 

error_7.py

from selenium import webdriver

driver = webdriver.Chrome('./chromedriver')

try:
    driver.get('http://news.naver.com')

    elem = driver.find_elements_by_id ('right.ranking_contents')

    news_list = elem.find_elements_by_tag_name('li')
    for news in news_list:
        print(news.text)
except Exception as e:
    print(e)
finally:
    driver.quit()

 

error_mail.py

from my_email import send_mail
send_mail('이태화', 'alghost.lee@gmail.com', '테스트내용')

 

my_email.py

from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from smtplib import SMTP_SSL

SMTP_SERVER='smtp.naver.com'
SMTP_PORT=465
SMTP_USER='lthlovelee'
# 실제 비밀번호를 입력해야 합니다.
SMTP_PASSWORD=''

def send_mail(name, addr, contents, attachment=False):
    msg = MIMEMultipart('alternative')

    if attachment:
        msg = MIMEMultipart('mixed')

    msg['From'] = SMTP_USER
    msg['To'] = addr
    msg['Subject'] = name+'님, 메일이 도착했습니다.'

    text = MIMEText(contents)
    msg.attach(text)

    if attachment:
        from email.mime.base import MIMEBase
        from email import encoders

        file_data = MIMEBase('application', 'octet-stream')
        f = open(attachment,'rb')
        file_contents = f.read()
        file_data.set_payload(file_contents)
        encoders.encode_base64(file_data)

        from os.path import basename
        filename = basename(attachment)
        file_data.add_header('Content-Disposition', 'attachment', filename=filename)
        msg.attach(file_data)

    smtp = SMTP_SSL(SMTP_SERVER, SMTP_PORT)
    smtp.login(SMTP_USER, SMTP_PASSWORD)
    smtp.sendmail('lthlovelee@naver.com', addr, msg.as_string())
    smtp.close()

 

my_error.py

def raise_error():
    a = 100
    print(a + 'string')
    return a
728x90
그리드형

댓글