Skip to content

antoniomb/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 web services client library (RESTful) with support for HTML, JSON, and XML services. Because mechanize is stateful and allow inspection of web resources, it naturally support GET-then-POST semantics.

Here is a 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 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 future development: #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!

About

mechanize for java

Resources

License

Stars

Watchers

Forks

Packages

No packages published