自如网房源释放自动提醒爬虫
主要功能为配置中未释放的房源释放后自动发邮件提醒,避免错过抢不到房子
使用方法:
_user = “发送邮箱”
_pwd = “发送邮箱的密码”
_to = “接收邮箱”
打开想抢的配置中的房源,
把代码中:http://www.ziroom.com/z/vr/60138527.html
改为你想抢的房子页面的链接再运行即可,有条件的可以放服务器上 nohup 24小时跑
#*-coding:utf-8-*-
import requests
import re
import smtplib
import time
from email.mime.text import MIMEText
def get163mail(retries):
_user = "sendemail@email.com"
_pwd = "password"
_to = "receiveemail@email.com"
msg = MIMEText(" quickly!!!!")
msg["Subject"] = "quicklyquickly!!!!"
msg["From"] = _user
msg["To"] = _to
try:
s = smtplib.SMTP_SSL("smtp.163.com", 465)
s.login(_user, _pwd)
s.sendmail(_user, _to, msg.as_string())
s.quit()
print "Send 163 Email Success!"
except smtplib.SMTPException, e:
print "retry.163mail..........,%s" % e
if retries > 0:
return get163mail(retries - 1)
else:
print "Send 163 Email Falied,%s" % e
print ("starting")
session = requests.session()
while 1:
try:
response_ziroom = session.get("http://www.ziroom.com/z/vr/60138527.html",
headers={
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:48.0) Gecko/20100101 Firefox/48.0'})
webpage_result = re.compile(r'title="配置中"')
analyze_result = re.search(webpage_result, response_ziroom._content)
if analyze_result:
print "still processing! wait!"
print time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
time.sleep(30)
else:
get163mail(5)
print time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
print "quick get it!"
break
except:
print "fuck socket is closed, retry..."
time.sleep(120)
continue