利用Python来监控女神的QQ空间!就算她屏蔽了,也阻止不了我!
谁还没暗恋过哪个妹子啊!当然那些暗恋的妹子应该称做为女生,今天就教大家一个简单的算是爬虫的案例吧!主要实现的功能就是:监控女神的 QQ空间,一旦女神发布新的说说,你的邮箱马上就会收到说说内容,是不是想了解一下 先看看代码运行效果图: 进群:548377875 ? 即可获取数十套PDF哦!源码已经展示给了大家~ PS:只有你有一台云服务器你就可以把程序24h运行起来 直接上代码:# -*- coding:utf-8 -*- from bs4 import BeautifulSoup from selenium import webdriver import time import random import os # by 留歌36 from email.mime.text import MIMEText import smtplib # 注意这里是配置你的源邮箱信息(发送邮件的邮箱) account = "" password = "" # 注意配置接收邮箱的信息 to = "*********@qq.com" # 注意是女神的qq号码 qq="你的女神的QQ号码" #使用Selenium的webdriver实例化一个浏览器对象,在这里使用Phantomjs driver = webdriver.PhantomJS(executable_path=r"F:phantomjs.exe") # 登录QQ空间 def get_shuoshuo(qq): try: # 注意更改http://user.qzone.qq.com/{女神的qq号码}/311 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,说明您没有登陆,现在开始登陆########") # 如果页面存在登录的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('你的女神的QQ号码') #判断好友空间是否设置了权限,通过判断是否存在元素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') shuoshuo = content[0].text shijian= stime[0].text context = '说说内容为:'+ shuoshuo # context = '说说内容为:' + shuoshuo + " " + '发表时间是:' + shijian cun = ''.join(context) if toCheck(cun): # 调用发送邮件的函数 print("##########准备发送邮件##########") send(to,"女神空间更新啦~~",context) print("##########发送邮件完成##########") print("##########准备保存说说##########") toSave(cun) print("##########保存说说完成##########") else: print('***还没有发布新的说说***') # driver.close() # driver.quit() # 发送邮件的函数 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) 你以为就完了吗?当然没有啦,光看到她的动态有啥用,肯定是要给女生的每条动态都自动点赞啊!知道你心里有她! 废话不多说!直接上代码吧! 源码如果看不清,请保存到本地,如果还是看不清,就私信小编!要自动给女神点赞的代码,小编看到会私信发给你的哦!至于屏蔽了的话,暂时用Python还没研究出来,不过女神有张良计,我有过墙梯嘛!方法还有其他的方法的!不外传哦!嘿嘿,万一腾讯搞我怎么办! (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |