我正在尋找寫有Web驅動程序的腳本,我需要等待通知電子郵件,然後需要從該電子郵件的鏈接獲取URL。如何從通知電子郵件中的鏈接獲取網址
0
A
回答
0
模式的識別URL(基於關閉RFC 3986)
private static final Pattern urlPattern = Pattern.compile(
"(?:^|[\\W])((ht|f)tp(s?):\\/\\/|www\\.)"
+ "(([\\w\\-]+\\.){1,}?([\\w\\-.~]+\\/?)*"
+ "[\\p{Alnum}.,%_=?&#\\-+()\\[\\]\\*[email protected]!:/{};']*)",
Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL);
//Usage: email content goes as input here..
Matcher matcher = urlPattern.matcher("foo bar http://example.com baz");
while (matcher.find()) {
int matchOffsetStart = matcher.start(1);
int matchOffsetEnd = matcher.end();
// now you have the offsets of a URL match
}
UPDATE: 如果你想讀像等消息頭,我會建議使用Mime4J
Message msg = new Message(new FileInputStream("mime.msg"));
msg.getFrom()
會給你從。同樣,你可以提取任何你想要的。
您更喜歡哪種語言解析電子郵件? –
我正在使用java作爲我的腳本 – Aminul