python3删除公司邮件
#coding:GBK
'''
Created on 2017年8月4日
@author: peiwenxiang
'''
import time
import re
import os
from selenium import webdriver
from selenium.webdriver.support import expected_conditions as EC
def email():
while True:
te = driver.find_element_by_xpath('//*[@id="panel"]/table/tbody/tr[2]/td/div[1]/div[2]/div/div[2]/span/span').text
num = re.findall('\d+', te)
#通过页数判断需要删除多少次,页数为0就不删除
if int(num[0]) == 0:
break
driver.find_element_by_name('checkall').click()#全选
time.sleep(1)
driver.find_element_by_xpath('//*[@id="panel"]/table/tbody/tr[2]/td/div[1]/div[1]/div/a[1]/span').click()#删除
time.sleep(2)
#判断alert提示是否存在
result = EC.alert_is_present()(driver)
if result:
alert = driver.switch_to_alert()
alert.accept()
time.sleep(2)
options = webdriver.ChromeOptions()
options.add_experimental_option("excludeSwitches", ["ignore-certificate-errors"])
driver = webdriver.Chrome(chrome_options=options)
driver.get('http://mail.vcredit.com/login.jsp')
driver.maximize_window()
driver.implicitly_wait(60)
time.sleep(2)
uname = driver.find_element_by_name('username')
uname.send_keys('*****@vcredit.com')
pword = driver.find_element_by_name('passwd')
pword.send_keys('******')
time.sleep(1)
driver.find_element_by_name('B1').click()
time.sleep(1)
#删除收件箱
driver.find_element_by_xpath('//*[@id="menumailbox"]/li[1]/a').click()
time.sleep(1)
email()
#删除已删除里面的邮件
driver.find_element_by_xpath('//*[@id="menumailbox"]/li[4]/a').click()
time.sleep(1)
email()
driver.quit()
#结束相关进程
ifexistchrome=os.system('tasklist|findstr "chrome.exe"')
ifexistDr=os.system('tasklist|findstr "chromedriver.exe"')
if ifexistchrome==0 and ifexistDr==0:
os.system('taskkill /f /im "chrome.exe"')
os.system('taskkill /f /im "chromedriver.exe"')
ifexistcmd=os.system('tasklist|findstr "chrome.exe"')
if ifexistcmd==0:
os.system('taskkill /f /im "cmd.exe"')
posted on 2017-08-04 16:24 sammy1989 阅读(1237) 评论(0) 编辑 收藏 举报