How to extract multiple email addresses from a web page using Jsoup?

I have list of sites from which i need to go to contact page and extract the email ids for each and every site using jsoup. I’m using the java.util.regex.Pattern to get email id code is shown below

Matcher m = Pattern.compile("[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+.[a-zA-Z0-9-.]+").matcher(doc.toString());
if (m.find()) {             

I encountered a some website where it contains multiple email addresses but above code gets only one email id which has encountered as first. I would like to get all the email id from that page.

I tried using below code but still getting all the junk

Elements elements =  doc.getElementsMatchingText(Pattern.compile("[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+.[a-zA-Z0-9-.]+"));
for(Element element: elements){

How can i get all the email ids from a web page?
please help me.

Source: regex

Leave a Reply