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

本文介绍如何使用Selenium自动化测试工具,实现从登录Outlook Web邮箱到抓取特定邮件内容的过程。包括使用Chrome浏览器驱动、定位页面元素、触发点击事件、解析邮件正文并提取关键信息等步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#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:\GitBase\xxx\Adaptors\3rdTools\chromedriver.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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值