如何导航到更正 Outlook 电子邮件内容中的"URL"



我成功地从JAVAX邮件中读取了outlook电子邮件。但当我试图得到";链接";在电子邮件正文中,它没有给出确切的URL,而是用一些额外的字符(如"(给出URL=3D*/&";。我试着使用下面的代码,但对我没有帮助。

public List<String> getUrlsFromMessage(Message message, String linkText) throws Exception {
String html = getMessageContent(message);
List<String> allMatches = new ArrayList<String>();
// (<a [^>]+>)
Matcher matcher = Pattern.compile(" (<a [^>]+>)" + linkText + "</a>").matcher(html);
while (matcher.find()) {
String aTag = matcher.group(1);
allMatches.add(aTag.substring(aTag.indexOf("http"), aTag.indexOf("">")));
}
return allMatches;
}

此外,我还将模式更改为

Pattern linkPattern = Pattern.compile(" <a\b[^>]*href="([^"]*)[^>]*>(.*?)</a>",
Pattern.CASE_INSENSITIVE | Pattern.DOTALL);`

但它仍然给了我错误的URL。

最后,我找到了一个使用StringBuilder检索准确URL的解决方案。我所做的是从字符串中删除不需要的字符,直到得到正确的URL。这可能不是一个好的编码实践,但这是唯一对我有效的工作

StringBuilder build = new StringBuilder(link);
build.deleteCharAt(43);// Shift the positions front.
build.deleteCharAt(51);
build.deleteCharAt(51);
driver.get(build.toString());

最新更新