Java Web Scraping in 2025: Proxies & Anti-Block Strategies





Michael Chen
Scraping Techniques
Diving Into Java Web Scraping: Modern Techniques for 2025
So, you want to scrape the web with Java? Good choice. Web scraping is a fantastic skill for anyone dealing with data today. It lets you gather information automatically, keep tabs on competitors, track market trends, and so much more. In a world driven by data, web scraping is your key to unlocking vast amounts of information.
But let's be real, it often feels like navigating a minefield.
Every website is a unique puzzle. Getting blocked is frustratingly common. Pulling the exact data you need from messy HTML can be a headache. And honestly, many Java web scraping tutorials feel like they're stuck in the past, recommending outdated libraries or complex regex solutions. Forget that noise.
This guide will show you a streamlined, modern approach to scraping any website with Java, even the tricky dynamic ones. We'll also cover essential techniques like avoiding blocks, grabbing screenshots, and extracting data efficiently.
Ready to level up your Java scraping game?
Understanding the Evolution of Java Web Scraping
Web scraping isn't a new concept, and the methods have evolved significantly. Initially, the common approach involved fetching a page's raw HTML source code. Then came the often-painful process of writing regular expressions (regex) to pinpoint and extract the desired data fragments.
While regex *can* work for extremely simple, static pages, it's brittle and notoriously difficult to get right. A tiny change on the target website could break your entire scraper.
Later, HTML parsers emerged. These libraries offered a more structured way to navigate the Document Object Model (DOM), simulating some browser functionalities. This was an improvement, but still struggled with the modern web. Today's websites heavily rely on JavaScript to load content dynamically, which basic HTML parsers simply can't handle effectively.
Most online guides stop there. But the story doesn't end with parsers. There's a much more robust way.
Meet Playwright: Your Go-To Java Library for Web Scraping
The most effective method for scraping modern websites is using a headless browser automation library. These tools control a real browser (like Chrome, Firefox, or WebKit) programmatically, allowing your code to interact with pages just like a human user would.
You might have heard of Puppeteer, a popular choice in the JavaScript world. While there isn't an official Puppeteer port for Java, the Java community has access to something arguably even better: Playwright.
Developed by Microsoft, Playwright builds upon the concepts of Puppeteer, offering a powerful, unified API across multiple languages, including Java. It lets you launch browser instances, navigate pages, interact with elements (clicking buttons, filling forms), execute JavaScript, and, crucially, extract data with precision.
Playwright's selectors are incredibly versatile. You can target elements using standard CSS selectors, XPath expressions, text content, attributes, and even relative layouts (e.g., "the button to the right of the price"). You can combine selectors too, like finding an element containing "Price" within a specific product container div. This makes extracting data from complex layouts much more manageable.
Furthermore, because Playwright controls a real browser, it naturally handles JavaScript rendering, executes network requests (XHR/fetch), and makes scraping dynamic content straightforward.
Let's see how to put it into practice.
Getting Started: Playwright, Java, and Practical Examples
We'll walk through the entire process, from setting up your development environment to actually extracting data. No prior scraping experience assumed!
Here’s our roadmap:
Set up a Java IDE (Eclipse)
Integrate Playwright using Maven
Troubleshoot common setup hurdles
Navigate to a website
Capture a screenshot
Connect securely using authenticated proxies
Extract specific data from a page
Let's build our scraper step-by-step.
Setting Up Your Java Web Scraping Environment
One great advantage of Java is its "write once, run anywhere" philosophy. Compile your scraper, and it should run on Windows, macOS, or Linux. This flexibility is great if you work across different machines.
First, you need a Java Development Kit (JDK) and an Integrated Development Environment (IDE). If you're new to Java development, Eclipse IDE for Java Developers is a solid, free choice that's relatively easy to start with. Make sure you have a JDK installed (Java 11 or later is recommended for Playwright).
Next, we need Maven, a build automation tool that manages project dependencies (like Playwright). Eclipse often comes bundled with Maven integration. If you're using a different IDE or running from the command line, you might need to install Maven separately.
In Eclipse, create a new Maven project:
Go to File > New > Other... (or use the shortcut, often Ctrl+N or Cmd+N).
Search for "Maven" and select Maven Project.
Click Next. Keep the default workspace location or choose your own. Crucially, check the box for Create a simple project (skip archetype selection). Click Next.
Enter your project details:
Group Id: Often a reverse domain name (e.g.,
com.example.scraper
)Artifact Id: Your project's name (e.g.,
java-scraper-demo
)Leave other fields like Version, Packaging as default.
Click Finish.

Your new project will appear in the Package Explorer. Give it a moment to initialize.
Now, find and open the pom.xml
file in your project's root directory. This file tells Maven about your project and its dependencies. Initially, it looks something like this:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example.scraper</groupId>
<artifactId>java-scraper-demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
</project>
We need to tell Maven to include Playwright. Add a <dependencies>
block before the closing </project>
tag:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example.scraper</groupId>
<artifactId>java-scraper-demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<!-- Add this section -->
<dependencies>
<dependency>
<groupId>com.microsoft.playwright</groupId>
<artifactId>playwright</artifactId>
<version>1.27.0</version> <!-- You can check for the latest version on Maven Central -->
</dependency>
</dependencies>
<!-- End of added section -->
</project>
Save the pom.xml
file. Maven should automatically download the Playwright library and its dependencies. You might see progress in the console or status bar.
Next, let's create our main Java class. Right-click the src/main/java
folder in the Package Explorer and select New > Package. Give it a name matching your Group ID (e.g., com.example.scraper
). Ensure Create package-info.java is unchecked.

Now, right-click the newly created package and select New > Class. Name your class (e.g., ScraperApp
). Importantly, check the box that says public static void main(String[] args) to automatically create the main method stub.

Click Finish. You now have a basic Java project set up with Playwright ready to go!
Your First Scrape: Taking a Screenshot with Java
With the setup complete, we can write some scraping code. Add your logic inside the `main` method. Your IDE will help identify errors as you type.
Let's start with a simple task: navigating to a website and taking a screenshot. This helps verify that Playwright is working correctly.
First, add the necessary import statements at the top of your ScraperApp.java
file (or whatever you named your class):
package com.example.scraper; // Use the package name you created
// Import core Playwright classes
import com.microsoft.playwright.*;
import com.microsoft.playwright.options.Proxy; // Needed later for proxies
// Import standard Java utilities
import java.nio.file.Paths;
// We might use these later, good to have:
// import java.util.Arrays;
// import java.util.List;
public class ScraperApp {
public static void main(String[] args) {
// Our scraping code will go here
}
}
Now, replace the comment inside the `main` method with the following code:
public static void main(String[] args) {
// Use try-with-resources to ensure Playwright resources are closed automatically
try (Playwright playwright = Playwright.create()) {
// Define browser launch options (we'll use this more later)
BrowserType.LaunchOptions launchOptions = new BrowserType.LaunchOptions();
// Set headless=false to watch the browser (optional, good for debugging)
// launchOptions.setHeadless(false);
// Launch a Chromium browser instance
try (Browser browser = playwright.chromium().launch(launchOptions)) {
// Create a new browser context (like an incognito window)
BrowserContext context = browser.newContext();
// Open a new page within the context
Page page = context.newPage();
// Navigate to a simple site that shows our IP address
System.out.println("Navigating to https://ipv4.icanhazip.com/ ...");
page.navigate("https://ipv4.icanhazip.com/");
System.out.println("Navigation complete.");
// Take a screenshot and save it
String screenshotPath = "screenshot-" + playwright.chromium().name() + ".png";
page.screenshot(new Page.ScreenshotOptions().setPath(Paths.get(screenshotPath)));
System.out.println("Screenshot saved to: " + screenshotPath);
// Clean up: Close the context
context.close();
// Browser is closed automatically by try-with-resources
System.out.println("Browser closed.");
}
} catch (PlaywrightException e) {
System.err.println("An error occurred during Playwright operation: " + e.getMessage());
e.printStackTrace();
}
System.out.println("Scraper finished.");
}
Let's break down this code:
Playwright.create()
initializes Playwright.playwright.chromium().launch(launchOptions)
starts a Chromium browser instance. You can also usefirefox()
orwebkit()
.browser.newContext()
creates an isolated browser session.context.newPage()
opens a new tab/page.page.navigate(...)
loads the specified URL.page.screenshot(...)
captures the current view and saves it to a file. We use `Paths.get()` for cross-platform compatibility and include the browser name in the filename.The `try-with-resources` statements ensure that `playwright` and `browser` instances are properly closed, even if errors occur.
Now, try running this code (Right-click the file > Run As > Java Application). Depending on your Java setup, you might encounter an error like:
Exception in thread "main" java.lang.Error: Unresolved compilation problem: References to interface static methods are allowed only at source level 1.8 or above
This usually means your project is configured for an older Java version. To fix it in Eclipse:
Right-click your project in the Package Explorer.
Select Properties.
Go to Java Build Path on the left, then select the Libraries tab.
Find the JRE System Library entry, select it, and click Edit....
Choose an appropriate JRE version (like JavaSE-11 or a newer installed JDK). If you don't see Java 11+, you might need to install it and configure it in Eclipse's preferences (Window > Preferences > Java > Installed JREs).
Click Finish, then Apply and Close.

After fixing the JRE setting, run the code again. You should see output in the console indicating navigation and screenshot success:

Where's the screenshot? Look in the root directory of your Eclipse project (usually inside your `eclipse-workspace` folder). You should find a file named `screenshot-chromium.png` (or similar depending on the browser used). Open it – it will show a simple page displaying your public IP address.
Success! But if you run scrapers frequently, especially against the same site, you'll likely get blocked based on your IP. Let's address that.
Evading Blocks: Using Authenticated Proxies with Playwright
While web scraping itself is generally legal for publicly accessible data, websites often employ measures to detect and block automated access. They don't appreciate bots overwhelming their servers or scraping proprietary data.
How do they detect scrapers? Several ways:
Request Headers: Simple HTTP clients might send minimal or unusual headers, flagging them as non-browser traffic. Playwright avoids this by using a real browser engine, sending realistic headers.
Behavior Patterns: Accessing pages too quickly, following predictable patterns, or having no pauses can signal automation.
IP Address: This is a major one. Making numerous requests from the same IP address in a short period is a classic sign of scraping activity, leading to IP bans or CAPTCHAs.
The most effective way to combat IP-based blocking is to use proxies. Proxies act as intermediaries, masking your real IP address. For robust scraping, Residential Proxies are often the best choice.
Evomi offers high-quality, ethically sourced residential proxies. These IPs belong to real devices, making your requests appear as genuine user traffic. This significantly reduces the chances of getting blocked. Evomi provides competitive pricing (Residential plans start at just $0.49/GB, Datacenter at $0.30/GB, Mobile at $2.2/GB, and Static ISP from $1/IP) and is based in Switzerland, known for its commitment to quality and privacy. We even offer a free trial for our Residential, Mobile, and Datacenter proxies if you want to test them out first.
To use Evomi proxies with Playwright, you'll need your proxy credentials and the correct endpoint details from your Evomi dashboard.
Endpoint: For residential proxies, use `rp.evomi.com`
Port: Use `1000` for HTTP, `1001` for HTTPS, or `1002` for SOCKS5.
Credentials: Your unique username and password.
Let's modify our previous screenshot example to use an authenticated Evomi proxy. We'll adjust the `launchOptions`:
public static void main(String[] args) {
try (Playwright playwright = Playwright.create()) {
BrowserType.LaunchOptions launchOptions = new BrowserType.LaunchOptions();
// launchOptions.setHeadless(false); // Optional: Watch the browser
// Configure the proxy settings
launchOptions.setProxy(
new Proxy("http://rp.evomi.com:1000") // Use Evomi endpoint and port
.setUsername("your-evomi-username") // Replace with your Evomi username
.setPassword("your-evomi-password") // Replace with your Evomi password
);
System.out.println("Using proxy: rp.evomi.com:1000");
try (Browser browser = playwright.chromium().launch(launchOptions)) {
BrowserContext context = browser.newContext();
Page page = context.newPage();
System.out.println("Navigating to https://ipv4.icanhazip.com/ via proxy...");
page.navigate("https://ipv4.icanhazip.com/");
System.out.println("Navigation complete.");
// Take screenshot (will show the proxy's IP)
String screenshotPath = "screenshot-proxy-" + playwright.chromium().name() + ".png";
page.screenshot(new Page.ScreenshotOptions().setPath(Paths.get(screenshotPath)));
System.out.println("Proxy screenshot saved to: " + screenshotPath);
context.close();
}
} catch (PlaywrightException e) {
System.err.println("An error occurred during Playwright operation: " + e.getMessage());
e.printStackTrace();
}
System.out.println("Scraper finished.");
}
Make sure you replace `"your-evomi-username"` and `"your-evomi-password"` with your actual Evomi credentials.
Run this updated code. The process is the same, but Playwright now routes the browser's traffic through the specified Evomi proxy server. Open the new screenshot (`screenshot-proxy-chromium.png`). You'll see a different IP address compared to your original screenshot – this is the IP address of the Evomi proxy!

By rotating through different residential IPs from Evomi for subsequent requests or scraping sessions, you make it extremely difficult for websites to identify and block your scraper based on its IP address.
Extracting Data with Java and Playwright
Screenshots are nice, but the real goal is usually data extraction. Playwright offers powerful methods to locate elements on a page and retrieve their content or interact with them.
Let's explore some common actions. The following code snippets should be placed inside the `try (Browser browser = ...)` block, replacing the previous screenshot logic.
Example 1: Extracting Text Content
We can use the `page.locator()` method with a CSS selector (or other selector types) to find an element and then `innerText()` to get its text.
// Assuming 'context' and 'page' are already created within the browser try block
page.navigate("https://playwright.dev/java/"); // Go to Playwright's Java docs
// Locate the main heading using its CSS class and get its text
String pageTitle = page.locator(".hero__title").innerText();
System.out.println("Extracted Title: " + pageTitle);
// Remember to close context if you're done
// context.close();
This code navigates to the Playwright Java documentation site, finds the element with the class `hero__title`, extracts its visible text content, and prints it to the console. You could store this `pageTitle` string, save it to a database, compare it, etc.
Example 2: Clicking an Element
You can simulate clicks on buttons, links, or other interactive elements using the `.click()` method after locating the element.
// Assuming 'context' and 'page' are created
page.navigate("https://playwright.dev/java/");
// Locate the search button by its CSS class and click it
System.out.println("Clicking search button...");
page.locator(".DocSearch-Button").click();
System.out.println("Search button clicked.");
// Let's take a screenshot to see the result (search modal opened)
page.screenshot(new Page.ScreenshotOptions().setPath(Paths.get("screenshot-search-modal.png")));
System.out.println("Screenshot after click saved.");
// context.close();
This snippet finds the search button and simulates a click, which should open the search overlay on the Playwright site. The screenshot confirms the action.

Example 3: Filling an Input Field
Interacting with forms often involves filling text boxes. Use the `.fill()` method after locating an input element.
// Assuming 'context' and 'page' are created
page.navigate("https://playwright.dev/java/");
// Click the search button first to reveal the input field
page.locator(".DocSearch-Button").click();
// Wait a tiny bit for the modal animation (better ways exist, like waitForSelector)
page.waitForTimeout(500); // 500 milliseconds
// Locate the search input field by its ID and type text into it
String searchTerm = "proxy";
System.out.println("Filling search input with: " + searchTerm);
page.locator("#docsearch-input").fill(searchTerm);
System.out.println("Input field filled.");
// Take a screenshot to verify
page.screenshot(new Page.ScreenshotOptions().setPath(Paths.get("screenshot-search-filled.png")));
System.out.println("Screenshot after filling input saved.");
// context.close();
This example first clicks the search button, then locates the search input field (which now should be visible) using its ID (`#docsearch-input`), and types the word "proxy" into it. The final screenshot shows the input field populated.

These examples are just scratching the surface. Playwright offers a rich set of methods for handling dropdowns, checkboxes, waiting for specific conditions, evaluating JavaScript, intercepting network requests, and much more, allowing you to automate almost any browser interaction.
Wrapping Up: Java, Playwright, and Smart Scraping
We've covered how to move beyond outdated Java scraping methods and leverage the power of Playwright for modern web automation. You learned how to set up your environment, navigate pages, take screenshots, extract data using various locators, and crucially, how to integrate reliable proxies like those from Evomi to avoid getting blocked.
Playwright combined with Java offers a robust platform for building sophisticated web scrapers capable of handling complex, dynamic websites. Remember that ethical considerations and respecting website terms of service are paramount when scraping.
Hopefully, this guide provides a solid foundation for your Java web scraping projects. Happy scraping!
Diving Into Java Web Scraping: Modern Techniques for 2025
So, you want to scrape the web with Java? Good choice. Web scraping is a fantastic skill for anyone dealing with data today. It lets you gather information automatically, keep tabs on competitors, track market trends, and so much more. In a world driven by data, web scraping is your key to unlocking vast amounts of information.
But let's be real, it often feels like navigating a minefield.
Every website is a unique puzzle. Getting blocked is frustratingly common. Pulling the exact data you need from messy HTML can be a headache. And honestly, many Java web scraping tutorials feel like they're stuck in the past, recommending outdated libraries or complex regex solutions. Forget that noise.
This guide will show you a streamlined, modern approach to scraping any website with Java, even the tricky dynamic ones. We'll also cover essential techniques like avoiding blocks, grabbing screenshots, and extracting data efficiently.
Ready to level up your Java scraping game?
Understanding the Evolution of Java Web Scraping
Web scraping isn't a new concept, and the methods have evolved significantly. Initially, the common approach involved fetching a page's raw HTML source code. Then came the often-painful process of writing regular expressions (regex) to pinpoint and extract the desired data fragments.
While regex *can* work for extremely simple, static pages, it's brittle and notoriously difficult to get right. A tiny change on the target website could break your entire scraper.
Later, HTML parsers emerged. These libraries offered a more structured way to navigate the Document Object Model (DOM), simulating some browser functionalities. This was an improvement, but still struggled with the modern web. Today's websites heavily rely on JavaScript to load content dynamically, which basic HTML parsers simply can't handle effectively.
Most online guides stop there. But the story doesn't end with parsers. There's a much more robust way.
Meet Playwright: Your Go-To Java Library for Web Scraping
The most effective method for scraping modern websites is using a headless browser automation library. These tools control a real browser (like Chrome, Firefox, or WebKit) programmatically, allowing your code to interact with pages just like a human user would.
You might have heard of Puppeteer, a popular choice in the JavaScript world. While there isn't an official Puppeteer port for Java, the Java community has access to something arguably even better: Playwright.
Developed by Microsoft, Playwright builds upon the concepts of Puppeteer, offering a powerful, unified API across multiple languages, including Java. It lets you launch browser instances, navigate pages, interact with elements (clicking buttons, filling forms), execute JavaScript, and, crucially, extract data with precision.
Playwright's selectors are incredibly versatile. You can target elements using standard CSS selectors, XPath expressions, text content, attributes, and even relative layouts (e.g., "the button to the right of the price"). You can combine selectors too, like finding an element containing "Price" within a specific product container div. This makes extracting data from complex layouts much more manageable.
Furthermore, because Playwright controls a real browser, it naturally handles JavaScript rendering, executes network requests (XHR/fetch), and makes scraping dynamic content straightforward.
Let's see how to put it into practice.
Getting Started: Playwright, Java, and Practical Examples
We'll walk through the entire process, from setting up your development environment to actually extracting data. No prior scraping experience assumed!
Here’s our roadmap:
Set up a Java IDE (Eclipse)
Integrate Playwright using Maven
Troubleshoot common setup hurdles
Navigate to a website
Capture a screenshot
Connect securely using authenticated proxies
Extract specific data from a page
Let's build our scraper step-by-step.
Setting Up Your Java Web Scraping Environment
One great advantage of Java is its "write once, run anywhere" philosophy. Compile your scraper, and it should run on Windows, macOS, or Linux. This flexibility is great if you work across different machines.
First, you need a Java Development Kit (JDK) and an Integrated Development Environment (IDE). If you're new to Java development, Eclipse IDE for Java Developers is a solid, free choice that's relatively easy to start with. Make sure you have a JDK installed (Java 11 or later is recommended for Playwright).
Next, we need Maven, a build automation tool that manages project dependencies (like Playwright). Eclipse often comes bundled with Maven integration. If you're using a different IDE or running from the command line, you might need to install Maven separately.
In Eclipse, create a new Maven project:
Go to File > New > Other... (or use the shortcut, often Ctrl+N or Cmd+N).
Search for "Maven" and select Maven Project.
Click Next. Keep the default workspace location or choose your own. Crucially, check the box for Create a simple project (skip archetype selection). Click Next.
Enter your project details:
Group Id: Often a reverse domain name (e.g.,
com.example.scraper
)Artifact Id: Your project's name (e.g.,
java-scraper-demo
)Leave other fields like Version, Packaging as default.
Click Finish.

Your new project will appear in the Package Explorer. Give it a moment to initialize.
Now, find and open the pom.xml
file in your project's root directory. This file tells Maven about your project and its dependencies. Initially, it looks something like this:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example.scraper</groupId>
<artifactId>java-scraper-demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
</project>
We need to tell Maven to include Playwright. Add a <dependencies>
block before the closing </project>
tag:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example.scraper</groupId>
<artifactId>java-scraper-demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<!-- Add this section -->
<dependencies>
<dependency>
<groupId>com.microsoft.playwright</groupId>
<artifactId>playwright</artifactId>
<version>1.27.0</version> <!-- You can check for the latest version on Maven Central -->
</dependency>
</dependencies>
<!-- End of added section -->
</project>
Save the pom.xml
file. Maven should automatically download the Playwright library and its dependencies. You might see progress in the console or status bar.
Next, let's create our main Java class. Right-click the src/main/java
folder in the Package Explorer and select New > Package. Give it a name matching your Group ID (e.g., com.example.scraper
). Ensure Create package-info.java is unchecked.

Now, right-click the newly created package and select New > Class. Name your class (e.g., ScraperApp
). Importantly, check the box that says public static void main(String[] args) to automatically create the main method stub.

Click Finish. You now have a basic Java project set up with Playwright ready to go!
Your First Scrape: Taking a Screenshot with Java
With the setup complete, we can write some scraping code. Add your logic inside the `main` method. Your IDE will help identify errors as you type.
Let's start with a simple task: navigating to a website and taking a screenshot. This helps verify that Playwright is working correctly.
First, add the necessary import statements at the top of your ScraperApp.java
file (or whatever you named your class):
package com.example.scraper; // Use the package name you created
// Import core Playwright classes
import com.microsoft.playwright.*;
import com.microsoft.playwright.options.Proxy; // Needed later for proxies
// Import standard Java utilities
import java.nio.file.Paths;
// We might use these later, good to have:
// import java.util.Arrays;
// import java.util.List;
public class ScraperApp {
public static void main(String[] args) {
// Our scraping code will go here
}
}
Now, replace the comment inside the `main` method with the following code:
public static void main(String[] args) {
// Use try-with-resources to ensure Playwright resources are closed automatically
try (Playwright playwright = Playwright.create()) {
// Define browser launch options (we'll use this more later)
BrowserType.LaunchOptions launchOptions = new BrowserType.LaunchOptions();
// Set headless=false to watch the browser (optional, good for debugging)
// launchOptions.setHeadless(false);
// Launch a Chromium browser instance
try (Browser browser = playwright.chromium().launch(launchOptions)) {
// Create a new browser context (like an incognito window)
BrowserContext context = browser.newContext();
// Open a new page within the context
Page page = context.newPage();
// Navigate to a simple site that shows our IP address
System.out.println("Navigating to https://ipv4.icanhazip.com/ ...");
page.navigate("https://ipv4.icanhazip.com/");
System.out.println("Navigation complete.");
// Take a screenshot and save it
String screenshotPath = "screenshot-" + playwright.chromium().name() + ".png";
page.screenshot(new Page.ScreenshotOptions().setPath(Paths.get(screenshotPath)));
System.out.println("Screenshot saved to: " + screenshotPath);
// Clean up: Close the context
context.close();
// Browser is closed automatically by try-with-resources
System.out.println("Browser closed.");
}
} catch (PlaywrightException e) {
System.err.println("An error occurred during Playwright operation: " + e.getMessage());
e.printStackTrace();
}
System.out.println("Scraper finished.");
}
Let's break down this code:
Playwright.create()
initializes Playwright.playwright.chromium().launch(launchOptions)
starts a Chromium browser instance. You can also usefirefox()
orwebkit()
.browser.newContext()
creates an isolated browser session.context.newPage()
opens a new tab/page.page.navigate(...)
loads the specified URL.page.screenshot(...)
captures the current view and saves it to a file. We use `Paths.get()` for cross-platform compatibility and include the browser name in the filename.The `try-with-resources` statements ensure that `playwright` and `browser` instances are properly closed, even if errors occur.
Now, try running this code (Right-click the file > Run As > Java Application). Depending on your Java setup, you might encounter an error like:
Exception in thread "main" java.lang.Error: Unresolved compilation problem: References to interface static methods are allowed only at source level 1.8 or above
This usually means your project is configured for an older Java version. To fix it in Eclipse:
Right-click your project in the Package Explorer.
Select Properties.
Go to Java Build Path on the left, then select the Libraries tab.
Find the JRE System Library entry, select it, and click Edit....
Choose an appropriate JRE version (like JavaSE-11 or a newer installed JDK). If you don't see Java 11+, you might need to install it and configure it in Eclipse's preferences (Window > Preferences > Java > Installed JREs).
Click Finish, then Apply and Close.

After fixing the JRE setting, run the code again. You should see output in the console indicating navigation and screenshot success:

Where's the screenshot? Look in the root directory of your Eclipse project (usually inside your `eclipse-workspace` folder). You should find a file named `screenshot-chromium.png` (or similar depending on the browser used). Open it – it will show a simple page displaying your public IP address.
Success! But if you run scrapers frequently, especially against the same site, you'll likely get blocked based on your IP. Let's address that.
Evading Blocks: Using Authenticated Proxies with Playwright
While web scraping itself is generally legal for publicly accessible data, websites often employ measures to detect and block automated access. They don't appreciate bots overwhelming their servers or scraping proprietary data.
How do they detect scrapers? Several ways:
Request Headers: Simple HTTP clients might send minimal or unusual headers, flagging them as non-browser traffic. Playwright avoids this by using a real browser engine, sending realistic headers.
Behavior Patterns: Accessing pages too quickly, following predictable patterns, or having no pauses can signal automation.
IP Address: This is a major one. Making numerous requests from the same IP address in a short period is a classic sign of scraping activity, leading to IP bans or CAPTCHAs.
The most effective way to combat IP-based blocking is to use proxies. Proxies act as intermediaries, masking your real IP address. For robust scraping, Residential Proxies are often the best choice.
Evomi offers high-quality, ethically sourced residential proxies. These IPs belong to real devices, making your requests appear as genuine user traffic. This significantly reduces the chances of getting blocked. Evomi provides competitive pricing (Residential plans start at just $0.49/GB, Datacenter at $0.30/GB, Mobile at $2.2/GB, and Static ISP from $1/IP) and is based in Switzerland, known for its commitment to quality and privacy. We even offer a free trial for our Residential, Mobile, and Datacenter proxies if you want to test them out first.
To use Evomi proxies with Playwright, you'll need your proxy credentials and the correct endpoint details from your Evomi dashboard.
Endpoint: For residential proxies, use `rp.evomi.com`
Port: Use `1000` for HTTP, `1001` for HTTPS, or `1002` for SOCKS5.
Credentials: Your unique username and password.
Let's modify our previous screenshot example to use an authenticated Evomi proxy. We'll adjust the `launchOptions`:
public static void main(String[] args) {
try (Playwright playwright = Playwright.create()) {
BrowserType.LaunchOptions launchOptions = new BrowserType.LaunchOptions();
// launchOptions.setHeadless(false); // Optional: Watch the browser
// Configure the proxy settings
launchOptions.setProxy(
new Proxy("http://rp.evomi.com:1000") // Use Evomi endpoint and port
.setUsername("your-evomi-username") // Replace with your Evomi username
.setPassword("your-evomi-password") // Replace with your Evomi password
);
System.out.println("Using proxy: rp.evomi.com:1000");
try (Browser browser = playwright.chromium().launch(launchOptions)) {
BrowserContext context = browser.newContext();
Page page = context.newPage();
System.out.println("Navigating to https://ipv4.icanhazip.com/ via proxy...");
page.navigate("https://ipv4.icanhazip.com/");
System.out.println("Navigation complete.");
// Take screenshot (will show the proxy's IP)
String screenshotPath = "screenshot-proxy-" + playwright.chromium().name() + ".png";
page.screenshot(new Page.ScreenshotOptions().setPath(Paths.get(screenshotPath)));
System.out.println("Proxy screenshot saved to: " + screenshotPath);
context.close();
}
} catch (PlaywrightException e) {
System.err.println("An error occurred during Playwright operation: " + e.getMessage());
e.printStackTrace();
}
System.out.println("Scraper finished.");
}
Make sure you replace `"your-evomi-username"` and `"your-evomi-password"` with your actual Evomi credentials.
Run this updated code. The process is the same, but Playwright now routes the browser's traffic through the specified Evomi proxy server. Open the new screenshot (`screenshot-proxy-chromium.png`). You'll see a different IP address compared to your original screenshot – this is the IP address of the Evomi proxy!

By rotating through different residential IPs from Evomi for subsequent requests or scraping sessions, you make it extremely difficult for websites to identify and block your scraper based on its IP address.
Extracting Data with Java and Playwright
Screenshots are nice, but the real goal is usually data extraction. Playwright offers powerful methods to locate elements on a page and retrieve their content or interact with them.
Let's explore some common actions. The following code snippets should be placed inside the `try (Browser browser = ...)` block, replacing the previous screenshot logic.
Example 1: Extracting Text Content
We can use the `page.locator()` method with a CSS selector (or other selector types) to find an element and then `innerText()` to get its text.
// Assuming 'context' and 'page' are already created within the browser try block
page.navigate("https://playwright.dev/java/"); // Go to Playwright's Java docs
// Locate the main heading using its CSS class and get its text
String pageTitle = page.locator(".hero__title").innerText();
System.out.println("Extracted Title: " + pageTitle);
// Remember to close context if you're done
// context.close();
This code navigates to the Playwright Java documentation site, finds the element with the class `hero__title`, extracts its visible text content, and prints it to the console. You could store this `pageTitle` string, save it to a database, compare it, etc.
Example 2: Clicking an Element
You can simulate clicks on buttons, links, or other interactive elements using the `.click()` method after locating the element.
// Assuming 'context' and 'page' are created
page.navigate("https://playwright.dev/java/");
// Locate the search button by its CSS class and click it
System.out.println("Clicking search button...");
page.locator(".DocSearch-Button").click();
System.out.println("Search button clicked.");
// Let's take a screenshot to see the result (search modal opened)
page.screenshot(new Page.ScreenshotOptions().setPath(Paths.get("screenshot-search-modal.png")));
System.out.println("Screenshot after click saved.");
// context.close();
This snippet finds the search button and simulates a click, which should open the search overlay on the Playwright site. The screenshot confirms the action.

Example 3: Filling an Input Field
Interacting with forms often involves filling text boxes. Use the `.fill()` method after locating an input element.
// Assuming 'context' and 'page' are created
page.navigate("https://playwright.dev/java/");
// Click the search button first to reveal the input field
page.locator(".DocSearch-Button").click();
// Wait a tiny bit for the modal animation (better ways exist, like waitForSelector)
page.waitForTimeout(500); // 500 milliseconds
// Locate the search input field by its ID and type text into it
String searchTerm = "proxy";
System.out.println("Filling search input with: " + searchTerm);
page.locator("#docsearch-input").fill(searchTerm);
System.out.println("Input field filled.");
// Take a screenshot to verify
page.screenshot(new Page.ScreenshotOptions().setPath(Paths.get("screenshot-search-filled.png")));
System.out.println("Screenshot after filling input saved.");
// context.close();
This example first clicks the search button, then locates the search input field (which now should be visible) using its ID (`#docsearch-input`), and types the word "proxy" into it. The final screenshot shows the input field populated.

These examples are just scratching the surface. Playwright offers a rich set of methods for handling dropdowns, checkboxes, waiting for specific conditions, evaluating JavaScript, intercepting network requests, and much more, allowing you to automate almost any browser interaction.
Wrapping Up: Java, Playwright, and Smart Scraping
We've covered how to move beyond outdated Java scraping methods and leverage the power of Playwright for modern web automation. You learned how to set up your environment, navigate pages, take screenshots, extract data using various locators, and crucially, how to integrate reliable proxies like those from Evomi to avoid getting blocked.
Playwright combined with Java offers a robust platform for building sophisticated web scrapers capable of handling complex, dynamic websites. Remember that ethical considerations and respecting website terms of service are paramount when scraping.
Hopefully, this guide provides a solid foundation for your Java web scraping projects. Happy scraping!
Diving Into Java Web Scraping: Modern Techniques for 2025
So, you want to scrape the web with Java? Good choice. Web scraping is a fantastic skill for anyone dealing with data today. It lets you gather information automatically, keep tabs on competitors, track market trends, and so much more. In a world driven by data, web scraping is your key to unlocking vast amounts of information.
But let's be real, it often feels like navigating a minefield.
Every website is a unique puzzle. Getting blocked is frustratingly common. Pulling the exact data you need from messy HTML can be a headache. And honestly, many Java web scraping tutorials feel like they're stuck in the past, recommending outdated libraries or complex regex solutions. Forget that noise.
This guide will show you a streamlined, modern approach to scraping any website with Java, even the tricky dynamic ones. We'll also cover essential techniques like avoiding blocks, grabbing screenshots, and extracting data efficiently.
Ready to level up your Java scraping game?
Understanding the Evolution of Java Web Scraping
Web scraping isn't a new concept, and the methods have evolved significantly. Initially, the common approach involved fetching a page's raw HTML source code. Then came the often-painful process of writing regular expressions (regex) to pinpoint and extract the desired data fragments.
While regex *can* work for extremely simple, static pages, it's brittle and notoriously difficult to get right. A tiny change on the target website could break your entire scraper.
Later, HTML parsers emerged. These libraries offered a more structured way to navigate the Document Object Model (DOM), simulating some browser functionalities. This was an improvement, but still struggled with the modern web. Today's websites heavily rely on JavaScript to load content dynamically, which basic HTML parsers simply can't handle effectively.
Most online guides stop there. But the story doesn't end with parsers. There's a much more robust way.
Meet Playwright: Your Go-To Java Library for Web Scraping
The most effective method for scraping modern websites is using a headless browser automation library. These tools control a real browser (like Chrome, Firefox, or WebKit) programmatically, allowing your code to interact with pages just like a human user would.
You might have heard of Puppeteer, a popular choice in the JavaScript world. While there isn't an official Puppeteer port for Java, the Java community has access to something arguably even better: Playwright.
Developed by Microsoft, Playwright builds upon the concepts of Puppeteer, offering a powerful, unified API across multiple languages, including Java. It lets you launch browser instances, navigate pages, interact with elements (clicking buttons, filling forms), execute JavaScript, and, crucially, extract data with precision.
Playwright's selectors are incredibly versatile. You can target elements using standard CSS selectors, XPath expressions, text content, attributes, and even relative layouts (e.g., "the button to the right of the price"). You can combine selectors too, like finding an element containing "Price" within a specific product container div. This makes extracting data from complex layouts much more manageable.
Furthermore, because Playwright controls a real browser, it naturally handles JavaScript rendering, executes network requests (XHR/fetch), and makes scraping dynamic content straightforward.
Let's see how to put it into practice.
Getting Started: Playwright, Java, and Practical Examples
We'll walk through the entire process, from setting up your development environment to actually extracting data. No prior scraping experience assumed!
Here’s our roadmap:
Set up a Java IDE (Eclipse)
Integrate Playwright using Maven
Troubleshoot common setup hurdles
Navigate to a website
Capture a screenshot
Connect securely using authenticated proxies
Extract specific data from a page
Let's build our scraper step-by-step.
Setting Up Your Java Web Scraping Environment
One great advantage of Java is its "write once, run anywhere" philosophy. Compile your scraper, and it should run on Windows, macOS, or Linux. This flexibility is great if you work across different machines.
First, you need a Java Development Kit (JDK) and an Integrated Development Environment (IDE). If you're new to Java development, Eclipse IDE for Java Developers is a solid, free choice that's relatively easy to start with. Make sure you have a JDK installed (Java 11 or later is recommended for Playwright).
Next, we need Maven, a build automation tool that manages project dependencies (like Playwright). Eclipse often comes bundled with Maven integration. If you're using a different IDE or running from the command line, you might need to install Maven separately.
In Eclipse, create a new Maven project:
Go to File > New > Other... (or use the shortcut, often Ctrl+N or Cmd+N).
Search for "Maven" and select Maven Project.
Click Next. Keep the default workspace location or choose your own. Crucially, check the box for Create a simple project (skip archetype selection). Click Next.
Enter your project details:
Group Id: Often a reverse domain name (e.g.,
com.example.scraper
)Artifact Id: Your project's name (e.g.,
java-scraper-demo
)Leave other fields like Version, Packaging as default.
Click Finish.

Your new project will appear in the Package Explorer. Give it a moment to initialize.
Now, find and open the pom.xml
file in your project's root directory. This file tells Maven about your project and its dependencies. Initially, it looks something like this:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example.scraper</groupId>
<artifactId>java-scraper-demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
</project>
We need to tell Maven to include Playwright. Add a <dependencies>
block before the closing </project>
tag:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example.scraper</groupId>
<artifactId>java-scraper-demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<!-- Add this section -->
<dependencies>
<dependency>
<groupId>com.microsoft.playwright</groupId>
<artifactId>playwright</artifactId>
<version>1.27.0</version> <!-- You can check for the latest version on Maven Central -->
</dependency>
</dependencies>
<!-- End of added section -->
</project>
Save the pom.xml
file. Maven should automatically download the Playwright library and its dependencies. You might see progress in the console or status bar.
Next, let's create our main Java class. Right-click the src/main/java
folder in the Package Explorer and select New > Package. Give it a name matching your Group ID (e.g., com.example.scraper
). Ensure Create package-info.java is unchecked.

Now, right-click the newly created package and select New > Class. Name your class (e.g., ScraperApp
). Importantly, check the box that says public static void main(String[] args) to automatically create the main method stub.

Click Finish. You now have a basic Java project set up with Playwright ready to go!
Your First Scrape: Taking a Screenshot with Java
With the setup complete, we can write some scraping code. Add your logic inside the `main` method. Your IDE will help identify errors as you type.
Let's start with a simple task: navigating to a website and taking a screenshot. This helps verify that Playwright is working correctly.
First, add the necessary import statements at the top of your ScraperApp.java
file (or whatever you named your class):
package com.example.scraper; // Use the package name you created
// Import core Playwright classes
import com.microsoft.playwright.*;
import com.microsoft.playwright.options.Proxy; // Needed later for proxies
// Import standard Java utilities
import java.nio.file.Paths;
// We might use these later, good to have:
// import java.util.Arrays;
// import java.util.List;
public class ScraperApp {
public static void main(String[] args) {
// Our scraping code will go here
}
}
Now, replace the comment inside the `main` method with the following code:
public static void main(String[] args) {
// Use try-with-resources to ensure Playwright resources are closed automatically
try (Playwright playwright = Playwright.create()) {
// Define browser launch options (we'll use this more later)
BrowserType.LaunchOptions launchOptions = new BrowserType.LaunchOptions();
// Set headless=false to watch the browser (optional, good for debugging)
// launchOptions.setHeadless(false);
// Launch a Chromium browser instance
try (Browser browser = playwright.chromium().launch(launchOptions)) {
// Create a new browser context (like an incognito window)
BrowserContext context = browser.newContext();
// Open a new page within the context
Page page = context.newPage();
// Navigate to a simple site that shows our IP address
System.out.println("Navigating to https://ipv4.icanhazip.com/ ...");
page.navigate("https://ipv4.icanhazip.com/");
System.out.println("Navigation complete.");
// Take a screenshot and save it
String screenshotPath = "screenshot-" + playwright.chromium().name() + ".png";
page.screenshot(new Page.ScreenshotOptions().setPath(Paths.get(screenshotPath)));
System.out.println("Screenshot saved to: " + screenshotPath);
// Clean up: Close the context
context.close();
// Browser is closed automatically by try-with-resources
System.out.println("Browser closed.");
}
} catch (PlaywrightException e) {
System.err.println("An error occurred during Playwright operation: " + e.getMessage());
e.printStackTrace();
}
System.out.println("Scraper finished.");
}
Let's break down this code:
Playwright.create()
initializes Playwright.playwright.chromium().launch(launchOptions)
starts a Chromium browser instance. You can also usefirefox()
orwebkit()
.browser.newContext()
creates an isolated browser session.context.newPage()
opens a new tab/page.page.navigate(...)
loads the specified URL.page.screenshot(...)
captures the current view and saves it to a file. We use `Paths.get()` for cross-platform compatibility and include the browser name in the filename.The `try-with-resources` statements ensure that `playwright` and `browser` instances are properly closed, even if errors occur.
Now, try running this code (Right-click the file > Run As > Java Application). Depending on your Java setup, you might encounter an error like:
Exception in thread "main" java.lang.Error: Unresolved compilation problem: References to interface static methods are allowed only at source level 1.8 or above
This usually means your project is configured for an older Java version. To fix it in Eclipse:
Right-click your project in the Package Explorer.
Select Properties.
Go to Java Build Path on the left, then select the Libraries tab.
Find the JRE System Library entry, select it, and click Edit....
Choose an appropriate JRE version (like JavaSE-11 or a newer installed JDK). If you don't see Java 11+, you might need to install it and configure it in Eclipse's preferences (Window > Preferences > Java > Installed JREs).
Click Finish, then Apply and Close.

After fixing the JRE setting, run the code again. You should see output in the console indicating navigation and screenshot success:

Where's the screenshot? Look in the root directory of your Eclipse project (usually inside your `eclipse-workspace` folder). You should find a file named `screenshot-chromium.png` (or similar depending on the browser used). Open it – it will show a simple page displaying your public IP address.
Success! But if you run scrapers frequently, especially against the same site, you'll likely get blocked based on your IP. Let's address that.
Evading Blocks: Using Authenticated Proxies with Playwright
While web scraping itself is generally legal for publicly accessible data, websites often employ measures to detect and block automated access. They don't appreciate bots overwhelming their servers or scraping proprietary data.
How do they detect scrapers? Several ways:
Request Headers: Simple HTTP clients might send minimal or unusual headers, flagging them as non-browser traffic. Playwright avoids this by using a real browser engine, sending realistic headers.
Behavior Patterns: Accessing pages too quickly, following predictable patterns, or having no pauses can signal automation.
IP Address: This is a major one. Making numerous requests from the same IP address in a short period is a classic sign of scraping activity, leading to IP bans or CAPTCHAs.
The most effective way to combat IP-based blocking is to use proxies. Proxies act as intermediaries, masking your real IP address. For robust scraping, Residential Proxies are often the best choice.
Evomi offers high-quality, ethically sourced residential proxies. These IPs belong to real devices, making your requests appear as genuine user traffic. This significantly reduces the chances of getting blocked. Evomi provides competitive pricing (Residential plans start at just $0.49/GB, Datacenter at $0.30/GB, Mobile at $2.2/GB, and Static ISP from $1/IP) and is based in Switzerland, known for its commitment to quality and privacy. We even offer a free trial for our Residential, Mobile, and Datacenter proxies if you want to test them out first.
To use Evomi proxies with Playwright, you'll need your proxy credentials and the correct endpoint details from your Evomi dashboard.
Endpoint: For residential proxies, use `rp.evomi.com`
Port: Use `1000` for HTTP, `1001` for HTTPS, or `1002` for SOCKS5.
Credentials: Your unique username and password.
Let's modify our previous screenshot example to use an authenticated Evomi proxy. We'll adjust the `launchOptions`:
public static void main(String[] args) {
try (Playwright playwright = Playwright.create()) {
BrowserType.LaunchOptions launchOptions = new BrowserType.LaunchOptions();
// launchOptions.setHeadless(false); // Optional: Watch the browser
// Configure the proxy settings
launchOptions.setProxy(
new Proxy("http://rp.evomi.com:1000") // Use Evomi endpoint and port
.setUsername("your-evomi-username") // Replace with your Evomi username
.setPassword("your-evomi-password") // Replace with your Evomi password
);
System.out.println("Using proxy: rp.evomi.com:1000");
try (Browser browser = playwright.chromium().launch(launchOptions)) {
BrowserContext context = browser.newContext();
Page page = context.newPage();
System.out.println("Navigating to https://ipv4.icanhazip.com/ via proxy...");
page.navigate("https://ipv4.icanhazip.com/");
System.out.println("Navigation complete.");
// Take screenshot (will show the proxy's IP)
String screenshotPath = "screenshot-proxy-" + playwright.chromium().name() + ".png";
page.screenshot(new Page.ScreenshotOptions().setPath(Paths.get(screenshotPath)));
System.out.println("Proxy screenshot saved to: " + screenshotPath);
context.close();
}
} catch (PlaywrightException e) {
System.err.println("An error occurred during Playwright operation: " + e.getMessage());
e.printStackTrace();
}
System.out.println("Scraper finished.");
}
Make sure you replace `"your-evomi-username"` and `"your-evomi-password"` with your actual Evomi credentials.
Run this updated code. The process is the same, but Playwright now routes the browser's traffic through the specified Evomi proxy server. Open the new screenshot (`screenshot-proxy-chromium.png`). You'll see a different IP address compared to your original screenshot – this is the IP address of the Evomi proxy!

By rotating through different residential IPs from Evomi for subsequent requests or scraping sessions, you make it extremely difficult for websites to identify and block your scraper based on its IP address.
Extracting Data with Java and Playwright
Screenshots are nice, but the real goal is usually data extraction. Playwright offers powerful methods to locate elements on a page and retrieve their content or interact with them.
Let's explore some common actions. The following code snippets should be placed inside the `try (Browser browser = ...)` block, replacing the previous screenshot logic.
Example 1: Extracting Text Content
We can use the `page.locator()` method with a CSS selector (or other selector types) to find an element and then `innerText()` to get its text.
// Assuming 'context' and 'page' are already created within the browser try block
page.navigate("https://playwright.dev/java/"); // Go to Playwright's Java docs
// Locate the main heading using its CSS class and get its text
String pageTitle = page.locator(".hero__title").innerText();
System.out.println("Extracted Title: " + pageTitle);
// Remember to close context if you're done
// context.close();
This code navigates to the Playwright Java documentation site, finds the element with the class `hero__title`, extracts its visible text content, and prints it to the console. You could store this `pageTitle` string, save it to a database, compare it, etc.
Example 2: Clicking an Element
You can simulate clicks on buttons, links, or other interactive elements using the `.click()` method after locating the element.
// Assuming 'context' and 'page' are created
page.navigate("https://playwright.dev/java/");
// Locate the search button by its CSS class and click it
System.out.println("Clicking search button...");
page.locator(".DocSearch-Button").click();
System.out.println("Search button clicked.");
// Let's take a screenshot to see the result (search modal opened)
page.screenshot(new Page.ScreenshotOptions().setPath(Paths.get("screenshot-search-modal.png")));
System.out.println("Screenshot after click saved.");
// context.close();
This snippet finds the search button and simulates a click, which should open the search overlay on the Playwright site. The screenshot confirms the action.

Example 3: Filling an Input Field
Interacting with forms often involves filling text boxes. Use the `.fill()` method after locating an input element.
// Assuming 'context' and 'page' are created
page.navigate("https://playwright.dev/java/");
// Click the search button first to reveal the input field
page.locator(".DocSearch-Button").click();
// Wait a tiny bit for the modal animation (better ways exist, like waitForSelector)
page.waitForTimeout(500); // 500 milliseconds
// Locate the search input field by its ID and type text into it
String searchTerm = "proxy";
System.out.println("Filling search input with: " + searchTerm);
page.locator("#docsearch-input").fill(searchTerm);
System.out.println("Input field filled.");
// Take a screenshot to verify
page.screenshot(new Page.ScreenshotOptions().setPath(Paths.get("screenshot-search-filled.png")));
System.out.println("Screenshot after filling input saved.");
// context.close();
This example first clicks the search button, then locates the search input field (which now should be visible) using its ID (`#docsearch-input`), and types the word "proxy" into it. The final screenshot shows the input field populated.

These examples are just scratching the surface. Playwright offers a rich set of methods for handling dropdowns, checkboxes, waiting for specific conditions, evaluating JavaScript, intercepting network requests, and much more, allowing you to automate almost any browser interaction.
Wrapping Up: Java, Playwright, and Smart Scraping
We've covered how to move beyond outdated Java scraping methods and leverage the power of Playwright for modern web automation. You learned how to set up your environment, navigate pages, take screenshots, extract data using various locators, and crucially, how to integrate reliable proxies like those from Evomi to avoid getting blocked.
Playwright combined with Java offers a robust platform for building sophisticated web scrapers capable of handling complex, dynamic websites. Remember that ethical considerations and respecting website terms of service are paramount when scraping.
Hopefully, this guide provides a solid foundation for your Java web scraping projects. Happy scraping!

Author
Michael Chen
AI & Network Infrastructure Analyst
About Author
Michael bridges the gap between artificial intelligence and network security, analyzing how AI-driven technologies enhance proxy performance and security. His work focuses on AI-powered anti-detection techniques, predictive traffic routing, and how proxies integrate with machine learning applications for smarter data access.