首页 技术 正文
技术 2022年11月15日
0 收藏 678 点赞 2,380 浏览 2869 个字

这个文章主要是在前一篇文章上新增了说说秒赞的功能

前一篇文章可以了解一下

那么,这次主要功能就是

监控女神的 QQ空间,一旦女神发布新的说说,马上点赞,你的邮箱马上就会收到说说内容,是不是想了解一下

直接上代码吧:

# -*- coding:utf-8 -*-
from selenium import webdriver
import time
import osfrom email.mime.text import MIMEText
import smtplib# by 留歌36#注意配置你的原始邮箱(发送邮件的邮箱)
account = "###"
password = "###"#注意配置你的接收邮箱
to = "###"#注意配置你女神的邮箱
qq="###"#使用Selenium的webdriver实例化一个浏览器对象,在这里使用Phantomjs
driver = webdriver.PhantomJS(executable_path=r"F:\\phantomjs.exe")# 登录QQ空间
def get_shuoshuo(qq):
try:
#注意配置你的女神的QQ号码http://user.qzone.qq.com/{你的女神的qq号码}/311'.format(qq)
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(10)
#注意配置你女神的qq号码
get_shuoshuo('###')
else:
print("#####,找到login_div,说明您没有登陆,现在开始登陆########")
# 如果页面存在登录的DIV,则模拟登录
driver.switch_to.frame('login_frame')
driver.find_element_by_id('switcher_plogin').click()
driver.find_element_by_id('u').clear() # 选择用户名框
#注意配置你的qq账号
driver.find_element_by_id('u').send_keys('###')
driver.find_element_by_id('p').clear()
#注意配置你的qq密码
driver.find_element_by_id('p').send_keys('###')
driver.find_element_by_id('login_button').click()
time.sleep(3)
print("#####登陆成功########")
#注意配置你女神的qq账号
get_shuoshuo('###')
#判断好友空间是否设置了权限,通过判断是否存在元素ID:QM_OwnerInfo_Icon
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')
btns = driver.find_elements_by_css_selector('.qz_like_btn.c_tx.mr8') shuoshuo = content[0].text
shijian= stime[0].text
context = '说说内容为:'+ shuoshuo
# context = '说说内容为:' + shuoshuo + " " + '发表时间是:' + shijian
cun = ''.join(context)
if toCheck(cun):
# 调用点赞的函数
print("##########准备点赞##########")
dian(btns)
print("##########点赞完成##########")
# 调用发送邮件的函数
print("##########准备发送邮件##########")
send(to, "女神空间更新啦~~", context)
print("##########发送邮件完成##########")
print("##########准备保存说说##########")
toSave(cun)
print("##########保存说说完成##########")
else:
print('pass,还没有更新新的说说')def dian(btns):
n = 0;
for btn in btns:
try:
if btn.is_displayed() == True:
if btn.text.find(u"赞") == 0:
btn.click()
n += 1
print ("点赞", n) except:
print("已经点赞过了第一条说说")
passdef 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('lhshuoshuo.txt'):
return True
else:
f = open('lhshuoshuo.txt','r')
existshuoshuo= f.readlines();
if data + '\n' in existshuoshuo:
return False
else:
return Truedef toSave(text):
f = open('lhshuoshuo.txt' , mode='a')
f.write(text+ '\n')
f.close()#让代码在服务器上一直跑着
while True:
get_shuoshuo(qq)

还是那样,如果你有什么好的建议可以留言呢

有什么问题也可以留言,我会尽量第一时间回复你的

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,086
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,561
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,410
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,183
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,820
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,903