• 自动化统计邮箱邮件


    #encode=utf-8
     
    class Practice(object):
        print u"这个方法的功能仅限于统计邮件"
        def __init__(self,url,driver):
            self.driver=driver
            self.url=url
     
        def brower_content(self):
    self.driver.get(self.url)
            mail_content=[]
            try:
                self.driver.switch_to_frame("login_frame")
                self.driver.find_element_by_id("img_out_1300994936").click()
                time.sleep(5)
                self.driver.switch_to.default_content()
                self.driver.find_element_by_id("folder_8").click()
                time.sleep(5)
                self.driver.switch_to_frame("mainFrame")
                self.driver.find_element_by_id("ckb_selectAll").click()
                time.sleep(1)
                self.driver.find_element_by_id("setAllReaded").click()
                time.sleep(1)
                result=self.driver.find_elements_by_xpath(".//table[@class='i  M']")
            except Exception:
                self.driver.switch_to_frame("login_frame")
                self.driver.find_element_by_id("switcher_plogin").click()
                self.driver.find_element_by_id("u").send_keys("1300994936@qq.com")
                self.driver.find_element_by_id("").send_keys(password)
                self.driver.find_element_by_id("login_button").click()
                time.sleep(5)
                self.driver.switch_to.default_content()
                self.driver.find_element_by_id("folder_8").click()
                time.sleep(5)
                self.driver.switch_to_frame("mainFrame")
                self.driver.find_element_by_id("ckb_selectAll").click()
                time.sleep(1)
                self.driver.find_element_by_id("setAllReaded").click()
                time.sleep(1)
                result=self.driver.find_elements_by_xpath(".//table[@class='i  M']")
            else:
                print u"获取邮箱内容失败"
            for i in result:
                if i.find_element_by_xpath(".//td[@class='tl_g tf']").text.decode("utf-8")[:-1]==u"光荣之路涨薪学习2群":
                    checkout=i.find_element_by_xpath(".//td[@class='dt']//div").text
                    print checkout[3:5],i.find_element_by_xpath(".//td[@class='gt tf']//u").text
                    if re.match(u"今天",checkout) and int(checkout[3:5])<9:
                        mail_content.append(i.find_element_by_xpath(".//td[@class='gt tf']//u").text)
                        print i.find_element_by_xpath(".//td[@class='gt tf']//u").text
                    elif re.match(u"昨天",checkout) and int(checkout[3:5])>=9:
                        mail_content.append(i.find_element_by_xpath(".//td[@class='gt tf']//u").text)
                        print i.find_element_by_xpath(".//td[@class='gt tf']//u").text
            self.driver.quit()
            return mail_content
     
    def Analysis(mail_content,file_name):
        print u"现在开始分析有效邮件数据"
        try:
            book=load_workbook(file_name)
            book1=book.get_sheet_by_name("Sheet1")
        except Exception,e:
            print u"excel对象获取失败,错误是: %s" % e.message
        book1.cell(row=1,column=2,value=time.strftime("%Y%m%d",time.localtime(time.time()-24*60*60)))
        for j in range(2,book1.max_row+1):
            book1.cell(row=j,column=3,value=u"")
        for i in mail_content:
            for j in range(2,book1.max_row+1):
                if book1.cell(row=j,column=1).value in i:
                    value=int(book1.cell(row=j,column=2).value)
                    book1.cell(row=j,column=2,value=value+1)
                    book1.cell(row=j,column=3,value=u"练习已提交")
        book.save(file_name)
     
    def brower_object(browser): 
        if browser.lower()=="ie":
    driver = webdriver.Ie()
            time.sleep(5)
            return driver
        elif browser.lower()=="firefox":
            driver=webdriver.Firefox()
            time.sleep(5)
            return driver
        else:
            print u"您输入的浏览器 %s 暂时还不支持驱动" % self.browser
     
    if __name__=="__main__":
        from selenium import webdriver
        import time
        from openpyxl import load_workbook
        import re
        import sys
        reload(sys)
        sys.setdefaultencoding("utf-8")
        driver=brower_object("firefox")
        practice=Practice("http://www.mail.qq.com",driver)
        mail_content=practice.brower_content()
        name="1"
        file_name=u"c://统计//统计.xlsx"
        Analysis(mail_content,file_name)
  • 相关阅读:
    完美图解教程 Linux环境VNC服务安装、配置与使用
    c语言中<stdbool.h>的使用
    UNIX文件结构(转自UNIX/AIX操作系统基础教程)
    umask
    在AIX环境为Oracle表空间增加裸设备(逻辑卷)
    面的面积大小合线的长度的判断。
    不用新浪博客了。以后的日常感悟也在这里写了, 新浪太烂了。 (感叹也没用,什么都写不出来。 )
    轴心工具的做法。
    选择因素随机的判断。
    上面发的那个完整版变量还有问题,难道我不是用英文输入法, 电脑不说谎 ,看来我是大意了。下面是最终版。
  • 原文地址:https://www.cnblogs.com/zhangtebie/p/11185933.html
Copyright © 2020-2023  润新知