如何使用 Robot Framework 解析电子邮件正文
How to parse email body with Robot Framework
我正在尝试使用 Robot Framework 中的 ImapLibrary2 从电子邮件 (gmail
) 中解析特定字符串。
这是我正在尝试使用的 代码 -
Email Parsing
Open Mailbox host=imap.gmail.com user=testing.abc@gmail.com password=Secret
${LATEST} = Wait For Email sender=support@abc.net timeout=60
${HTML} = Get Email Body ${LATEST}
${Paser_Body}= Get Regexp Matches ${HTML} ^.*([a-zA-Z]+(\d[a-zA-Z]+)+).*$
Log ${Paser_Body}
Close Mailbox
电子邮件正文是-
Reset Your Password
To reset the password for the user account associated with your email, use the code below and follow the procedure on the application. If you don't want to reset your password, please disregard this email.
ASNjfO24j6RrwKg6PP3scO1EeivA88
Thanks,
Abc Support Team
我想从电子邮件中提取令牌 ASNjfO24j6RrwKg6PP3scO1EeivA88
,但是 运行 代码,我得到一个空输出。
输出-
Starting test: Test.Email Parsing
20210317 11:53:21.493 : INFO : ${LATEST} = 29
20210317 11:53:21.630 : INFO : ${HTML} =
<tbody>
<tr>
<td style="padding:40px 0 0 0;">
<p style="color:#000;font-size: 16px;line-height:24px;font-family:'HelveticaNeue','Helvetica Neue',Helvetica,Arial,sans-serif;font-weight:no...
20210317 11:53:21.630 : INFO : ${Paser_Body} = []
20210317 11:53:21.630 : INFO : []
Ending test: Test .Email Parsing
我做错了什么?
我能够通过-
解析所需的元素
Step 1: Remove unnecessary string using Regular Expression
Step 2: Splitting the string
Step 3: Getting the required element from the list
这里是示例代码-
Open Mailbox host=imap.gmail.com user=testing.abc@gmail.com password=Secret
${LATEST} = Wait For Email sender=support@abc.net timeout=60
${HTML} = Get Email Body ${LATEST}
${Paser_Body}= Remove String Using Regexp ${HTML} (<.*?>) #remove tags
${Parsed_Token}= Split String ${Parser_Body_Text}
${Parsed_Token}= Get From List ${Parsed_Token} 20 #position in the list
Close Mailbox
我正在尝试使用 Robot Framework 中的 ImapLibrary2 从电子邮件 (gmail
) 中解析特定字符串。
这是我正在尝试使用的 代码 -
Email Parsing
Open Mailbox host=imap.gmail.com user=testing.abc@gmail.com password=Secret
${LATEST} = Wait For Email sender=support@abc.net timeout=60
${HTML} = Get Email Body ${LATEST}
${Paser_Body}= Get Regexp Matches ${HTML} ^.*([a-zA-Z]+(\d[a-zA-Z]+)+).*$
Log ${Paser_Body}
Close Mailbox
电子邮件正文是-
Reset Your Password
To reset the password for the user account associated with your email, use the code below and follow the procedure on the application. If you don't want to reset your password, please disregard this email.
ASNjfO24j6RrwKg6PP3scO1EeivA88
Thanks,
Abc Support Team
我想从电子邮件中提取令牌 ASNjfO24j6RrwKg6PP3scO1EeivA88
,但是 运行 代码,我得到一个空输出。
输出-
Starting test: Test.Email Parsing
20210317 11:53:21.493 : INFO : ${LATEST} = 29
20210317 11:53:21.630 : INFO : ${HTML} =
<tbody>
<tr>
<td style="padding:40px 0 0 0;">
<p style="color:#000;font-size: 16px;line-height:24px;font-family:'HelveticaNeue','Helvetica Neue',Helvetica,Arial,sans-serif;font-weight:no...
20210317 11:53:21.630 : INFO : ${Paser_Body} = []
20210317 11:53:21.630 : INFO : []
Ending test: Test .Email Parsing
我做错了什么?
我能够通过-
解析所需的元素Step 1: Remove unnecessary string using Regular Expression
Step 2: Splitting the string
Step 3: Getting the required element from the list
这里是示例代码-
Open Mailbox host=imap.gmail.com user=testing.abc@gmail.com password=Secret
${LATEST} = Wait For Email sender=support@abc.net timeout=60
${HTML} = Get Email Body ${LATEST}
${Paser_Body}= Remove String Using Regexp ${HTML} (<.*?>) #remove tags
${Parsed_Token}= Split String ${Parser_Body_Text}
${Parsed_Token}= Get From List ${Parsed_Token} 20 #position in the list
Close Mailbox