# -*- coding: utf-8 -*- from selenium import webdriver from time import sleep from email.mime.text import MIMEText from email.header import Header from email.mime.multipart import MIMEMultipart from email.mime.application import MIMEApplication options = webdriver.ChromeOptions() prefs = {'profile.default_content_settings.popups': 0, 'download.default_directory': 'C:/Users/fxia/Desktop/shiftplan'} options.add_experimental_option('prefs', prefs) driver = webdriver.Chrome(executable_path='C:/Users/fxia/Downloads/chromedriver_win32/chromedriver.exe', chrome_options=options) driver.get('http://workit.nnitcorp.com/Departments/086-0961/Middleware/Shared%20Documents/Teamet/Shiftplan24_7_v1.xls') #driver.find_element_by_xpath('C:/Users/fxia/Desktop/shiftplan/a[text()="testsaveas.zip"]').click() sleep(3) driver.quit() ########### import win32com.client as win32 import xlrd import time outlook = win32.Dispatch('outlook.application') mail = outlook.CreateItem(0) receivers = ['4422@qq.com'] mail.To = receivers[0] #day = time.strftime("%d/%m/%Y") mail.Subject ='shiftplan' workbook = xlrd.open_workbook('C:/Users/fxia/Desktop/shiftplan/Shiftplan24_7_v1.xls') mySheet = workbook.sheet_by_index(0) nrows = mySheet.nrows ################## mail.body=(''' this is a test <br>/n</br> test2 ''') ####################### mail.Attachments.Add('C:/Users/fxia/Desktop/shiftplan/Shiftplan24_7_v1.xls') mail.Send() ### sleep(30) import os my_file = 'C:/Users/fxia/Desktop/shiftplan/Shiftplan24_7_v1.xls' if os.path.exists(my_file): #删除文件,可使用以下两种方法。 #os.remove(my_file) os.unlink(my_file) else: print ('no such file:%s'%my_file)