EP申请爬虫代码

刚来新加坡的时候,因为要申请EP,每次查询状态,需要进入网站,输入用户名、护照名、出生日期,的确很麻烦,所以用Python写了一个脚本,可以自动运行,然后结果就会输出你的状态 Pending/Reject/Approve。

#!/usr/bin/python
# -*- coding: utf-8 -*-
# coding: utf-8
import urllib2
import urllib
import re
import smtplib
import sys
import time
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.mime.image import MIMEImage

def sleeptime(hour,min,sec):
    return hour*3600 + min*60 + sec;

def sendSbmail(to_sbmail,status):
    # 发送的邮箱
    from_mail='[email protected]'
    to_mail=to_sbmail
     
    reload(sys)
    sys.setdefaultencoding('gb2312')

    msg=MIMEMultipart()
    msg['From']=from_mail
    msg['To']=to_mail
    msg['Subject']='请关注status'+status
    # body内容
    body='状态'+ status
    # 如果图片的话,可以在这里通过HTML格式添加
    con=MIMEText('%s

' % body,'html',_charset="utf-8") msg.attach(con) # 配置邮箱的STMP server=smtplib.SMTP('smtp.126.com') # 例如 [email protected] 密码 server.login('邮箱名称','邮箱密码') # 发送邮件给我 server.sendmail(from_mail,to_mail,msg.as_string()) server.quit() def sendData(): formdata = {"requesterNRICFIN":"E70330000","requesterName":"Duan Duan","travelDocNo":"E70330000","trvDateBirth":"04/12/1994"} data = urllib.urlencode(formdata) request = urllib2.Request('https://eponline.mom.gov.sg/epol/PEPOLENQM008SubmitAction.do', data = data) try: response = urllib2.urlopen(request) except Exception as ex: print ex return 1 else: content = response.read() t = re.search('Pending', content) a = re.search('Rejected', content) b = re.search('prove', content) if t: print 'Pending', return 1 if a: sendSbmail('你的邮箱@me.com', 'Rejected') return 0 if b: sendSbmail('你的邮箱@me.com', 'prove') return 0 return 1 return 1 if __name__ == "__main__": second = sleeptime(0,0,300); status = 1 i = 0 while status: i = i+1 print i, status = sendData() time.sleep(second);

你可能感兴趣的:(EP申请爬虫代码)