这篇文章将为大家详细讲解有关Python如何实现利用163邮箱远程关电脑脚本,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。
halla.py
import requests import mechanicalsoup import bs4 import re import TEST import time import argparse from datetime import datetime import lxml parser = argparse.ArgumentParser(description='Login to GitHub.') parser.add_argument("username") parser.add_argument("password") args = parser.parse_args() n = 0 startime = datetime.strptime(datetime.now().strftime('%Y-%m-%d %H:%M:%S'),'%Y-%m-%d %H:%M:%S') while True: #打开“浏览器” browser = mechanicalsoup.Browser() #第一个页面url url = "http://reg.163.com/logins.jsp?type=1&product=mail163&url=http://entry.mail.163.com/coremail/fcg/ntesdoor2?lightweight%3D1%26verifycookie%3D1%26language%3D-1%26style%3D1" #打开网易登录页面 login_page = browser.get(url) #输入账户密码然后提交表单 login_form = login_page.soup.select("#fLogin")[0] login_form.select("#username")[0]['value'] = args.username login_form.select("#password")[0]['value'] = args.password page2 = browser.submit(login_form, login_page.url) #获取page2内容 page2_soup = bs4.BeautifulSoup(page2.content) #用page2的cookies登录网易邮箱 cookie = page2.cookies.get_dict() page3 = browser.get('http://entry.mail.163.com/coremail/fcg/ntesdoor2') #获取page3的url中的sid,给出XMLurl sid = re.findall(r'(?<==).*(?=&)',page3.url) XMLurl = 'http://mail.163.com/js6/s?sid='+sid[0]+'&func=mbox:listMessages&topNav_mobileIcon_show=1&TopTabReaderShow=1&TopTabLofterShow=1&welcome_welcomemodule_mailrecom_click=1&LeftNavfolder1Click=1&mbox_folder_enter=1' #打开XMLurl页面,获取邮件 page4 = browser.post(XMLurl) with open(r'q.xml','w',encoding='utf-8') as q: q.write(page4.text) TEST.PPP(r'q.xml',startime).ppp() n+=1 print("循环执行第"+str(n)+'次') time.sleep(30)
TEST.py
import lxml.etree import os from datetime import datetime class PPP(): def __init__(self, src, startime): self.src = src self.startime = startime def ppp(self): parser = lxml.etree.XMLParser(recover=True) tree = lxml.etree.parse(self.src, parser) root = tree.getroot() array = root.find('array') for objects in array: FLAG = False for items in objects: if items.get('name') == 'subject': if items.text == '999': FLAG = True if items.get('name') == 'sentDate': raw_sentData = items.text sentData = datetime.strptime(raw_sentData,'%Y-%m-%d %H:%M:%S') if self.startime<sentData and FLAG==True: print('shutdown -s -t 60')
关于“Python如何实现利用163邮箱远程关电脑脚本”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。