Skip to content

sospartan/mechanize

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mechanize for java Build Status

mechanize is a stateful HTTP client library (RESTful) with support for HTML, JSON, and (soon) XML web services. mechanize can scrape HTML, crawl web pages, and use JSON and XML web services. This implementation of mechanize is written in Java to be available on the JVM, and specifically compatible with Android. It utilizes HttpClient for HTTP handling. Because mechanize is stateful and allow inspection of web resources, it naturally support GET-then-POST semantics.

Here is a sample testcase showing mechanize at work with HTML:

	@Test public void testGooglePageSearchForm() {
		MechanizeAgent agent = new MechanizeAgent();
		Document page = agent.get("http://www.google.com");
		Form form = page.form("f");
		form.get("q").set("mechanize java");
		Resource response = form.submit();
		assertTrue(response.getTitle().startsWith("mechanize java"));
	}

Here is a sample testcase showing mechanize using a Google JSON web service:

	@Test
	public void testGoogleApi() throws JSONException {
		MechanizeAgent agent = new MechanizeAgent();
		JsonDocument json = agent.doRequest(googleUrl).add("shortUrl", shortUrl).add("projection", "FULL").get();

		assertEquals(longUrl, json.getRoot().find("longUrl").getValue());

		String value = json.getRoot().find("analytics month countries#US count").getValue();
		assertTrue(value, Integer.valueOf(value)>=1);
	}

What to expect from near future development: #28 Caching and Conditional GETs, #61 XML Support

Release log:

Download the code from https://github.com/GistLabs/mechanize/downloads, or use a Maven repository client:

  <dependency>
    <groupId>com.gistlabs</groupId>
    <artifactId>mechanize</artifactId>
    <version>0.11.0</version>
  </dependency>

See the Mechanize Wiki for more details!