jBrowserDriver是一款采用纯Java编写的无图形化浏览器,基于WebKit,和 Seleium 兼容。
通过Mave安装:
<depedecy> <groupId>com.machiepublishers</groupId> <artifactId>jbrowserdriver</artifactId> <versio>0.16.1</versio></depedecy>使用示例代码:
import org.opeqa.seleium.WebDriver;import com.machiepublishers.jbrowserdriver.Timezoe;import com.machiepublishers.jbrowserdriver.JBrowserDriver;import com.machiepublishers.jbrowserdriver.Settigs;public class Example { public static void mai(Strig[] args) { // You ca optioally pass a Settigs object here, // costructed usig Settigs.Builder JBrowserDriver driver = ew JBrowserDriver(Settigs.builder(). timezoe(Timezoe.AMERICA_NEWYORK).build()); // This will block for the page load ad ay // associated AJAX requests driver.get("https://example.com"); // You ca get status code ulike other Seleium drivers. // It blocks for AJAX requests ad page loads after clicks // ad keyboard evets. System.out.pritl(driver.getStatusCode()); // Returs the page source i its curret state, icludig // ay DOM updates that occurred after page load System.out.pritl(driver.getPageSource()); // Close the browser. Allows this thread to termiate. driver.quit(); }}
评论