通过outlook的web邮箱获取指定邮件内容的邮件

#encoding=utf-8
from selenium import webdriver
import time,re

class GetFiletestFile(object):
def __init__(self):
print "init work..."
self.driver=webdriver.Chrome(executable_path=r"D:GitBasexxxAdaptors3rdToolschromedriver.exe")

def GetOutlookInfo(self):
url="https://mail.myoutlook/owa/#path=/mail"
self.driver.get(url)
#登录outlook的web邮箱
username=self.driver.find_element_by_id("username")
username.send_keys("myname")
password=self.driver.find_element_by_id("password")
password.send_keys("mypwd")
self.driver.find_element_by_xpath("//div[@class='signinbutton']").click()
time.sleep(3)
#点击收件箱
self.driver.switch_to.default_content()
self.driver.find_element_by_xpath("//span[@id='_ariaId_51.folder']").click()
time.sleep(2)
#通过xpath的相对路径方式定位(这里采用了两个//,相对的相对),传入的参数双引号和单引号需要嵌套使用
contents=self.driver.find_elements_by_xpath("//div[@autoid='_lv_i']//span[contains(@autoid,'_lv_b')]")
try:
results=[]
for content in contents:
if (u"天擎提测"in content.text or u"Qbuild"in content.text) and "6.3" in content.text:
#print content.text
#需要触发标题的点击动作,才能获取到某个标题的邮件内容
content.click()
time.sleep(3)
mailbody=self.driver.find_element_by_xpath("//div[@class='conductorContent']//div[@id='Item.MessagePartBody']/div/div/div")
#匹配filetest路径
if u"filetest提测路径" in mailbody.text:
#print mailbody.text
pattern=re.compile(r"haha@1192.0.5.8/output/test/.*qbuild",re.I)
res=pattern.search(mailbody.text)
if res:
#print res.group()
results.append(res.group())
#将提测结果列表去重返回
return list(set(results))
except Exception as e:
print e
finally:
self.driver.quit()
print "work done"

if __name__ == '__main__':

obj=GetFiletestFile()
print obj.GetOutlookInfo()

原文地址:https://www.cnblogs.com/skyer/p/6728210.html