主要实现的功能就是:监控女神的 QQ空间,一旦女神发布新的说说,你的邮箱马上就会收到说说内容,是不是想了解一下
先看看代码运行效果图:


PS:只有你有一台云服务器你就可以把程序24h运行起来
from bs4 import BeautifulSoup
from selenium import webdriver
import time
import random
import os
from email.mime.text import MIMEText
import smtplib
account = ""
password = ""
to = "893861319@qq.com"
qq="你的女神的QQ号码"
driver = webdriver.PhantomJS(executable_path=r"F:\phantomjs.exe")
def get_shuoshuo(qq):
try:
driver.get('http://user.qzone.qq.com/你的女神的QQ号码/311'.format(qq))
time.sleep(5)
driver.find_element_by_id('login_div')
except:
print("#####,没有找到login_div,说明您在线########")
sea()
time.sleep(30)
get_shuoshuo('你的女神的QQ号码')
else:
print("#####,找到login_div,说明您没有登陆,现在开始登陆########")
driver.switch_to.frame('login_frame')
driver.find_element_by_id('switcher_plogin').click()
driver.find_element_by_id('u').clear()
driver.find_element_by_id('u').send_keys('####')
driver.find_element_by_id('p').clear()
driver.find_element_by_id('p').send_keys('#####')
driver.find_element_by_id('login_button').click()
time.sleep(3)
print("#####登陆成功########")
get_shuoshuo('你的女神的QQ号码')
driver.implicitly_wait(3)
def sea():
try:
driver.find_element_by_id('QM_OwnerInfo_Icon')
b = True
except:
b = False
if b == True:
driver.switch_to.frame('app_canvas_frame')
content = driver.find_elements_by_css_selector('.content')
stime = driver.find_elements_by_css_selector('.c_tx.c_tx3.goDetail')
shuoshuo = content[0].text
shijian= stime[0].text
context = '说说内容为:'+ shuoshuo
cun = ''.join(context)
if toCheck(cun):
print("##########准备发送邮件##########")
send(to, "女神空间更新啦~~", context)
print("##########发送邮件完成##########")
print("##########准备保存说说##########")
toSave(cun)
print("##########保存说说完成##########")
else:
print('***还没有发布新的说说***')
def send(to, title, content):
msg = MIMEText(content)
msg['Content-Type'] = 'text/plain; charset="utf-8"'
msg['Subject'] = title
msg['From'] = account
msg['To'] = to
try:
smtp = smtplib.SMTP()
smtp.connect('smtp.163.com')
smtp.login(account, password)
smtp.sendmail(account, to, msg.as_string())
smtp.close()
except Exception as e :
print (str(e))
def toCheck(data):
if not os.path.exists('shuoshuo.txt'):
return True
else:
f = open('shuoshuo.txt','r')
existshuoshuo= f.readlines();
if data + '
' in existshuoshuo:
return False
else:
return True
def toSave(text):
f = open('shuoshuo.txt' , mode='a')
f.write(text+ '
')
f.close()
while True:
get_shuoshuo(qq)
*如果你有什么好的建议可以留言呢
有什么问题也可以留言,我会尽量第一时间回复你的*