친구가 phpschool에서 알바 하는데 글 뜨면 자동으로 메일 오게 만드는 프로그램을 C#으로 만들었다고 하더라구요. 그래서 저도 심심해서 한번 python으로 만들어 봤습니다.
__author__ = 'yumere'
from bs4 import BeautifulSoup
import urllib
import time
import smtplib
from email.mime.text import MIMEText
url = "http://phpschool.com/gnuboard4"
tmp = raw_input("List NO:")
NO=int(tmp)
username = "yumere7833@gmail.com"
passwd = "****"
HOST = 'smtp.gmail.com'
me = 'yumere7833@gmail.com'
rec = 'yumere7833@gmail.com'
while(1):
html_source = urllib.urlopen("http://phpschool.com/gnuboard4/bbs/board.php?bo_table=old_job&page=1").read()
soup = BeautifulSoup(html_source)
table = soup.find_all('table', {'class':'board_table'})
first_tb = table[0]
tr = first_tb('tr')
#print tr[5]
if NO != int(tr[5].td.string.replace(',', '')):
NO=int(tr[5].td.string.replace(',', ''))
tmpStr = tr[5].td.next.next.next.next.next.next.next.a['href']
tmpUrl=url
tmpUrl+=tmpStr[2:]
print tmpUrl
contents = """
Subject : %s
URL : %s
""" % (tr[5].td.next.next.next.next.next.next.next.a.string, tmpUrl)
msg = MIMEText(contents, _charset='euc-kr')
msg['Subject'] = 'PHPSchool 알바'
msg['From'] = me
msg['To'] = rec
server = smtplib.SMTP(HOST, 587)
server.ehlo()
server.starttls()
server.ehlo()
server.login(username, passwd)
server.sendmail(me, [rec], msg.as_string())
continue
#server.quit()
print("There is no")
time.sleep(5)