Here is a Java code that can be used to scrape email addresses from a webpage:
import java.io.IOException;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
public class EmailScraper {
public static void main(String[] args) throws IOException {
// Get the URL from user input
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the URL of the webpage to scrape: ");
String url = scanner.nextLine();
// Connect to the webpage
Document doc = Jsoup.connect(url).get();
// Get all the text from the webpage
String webpageText = doc.text();
// Regular expression to match email addresses
String regex = "(\\w+)(\\.|_)?(\\w*)@(\\w+)(\\.(\\w+))+";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(webpageText);
// Print all matched email addresses
while (matcher.find()) {
System.out.println(matcher.group());
}
}
}
This code uses the JSoup library to connect to the specified URL and retrieve the text of the webpage. It then uses a regular expression to search for any email addresses in the text, and prints them to the console.
Note that this is just a basic example, and it may not work perfectly in all cases. Email addresses can be written in many different ways, so you may need to modify the regular expression to match the specific format used on the webpage you are scraping. Additionally, some website have anti-scraping policies and may block your IP if you scrape their pages too much.
I trust this helps you! if you have any query you can ask me.
