Mechanize for Java

mechanize for Java

mechanize is a stateful HTTP web services client with support for HTML, JSON, and XML services.

The 1.x release includes the HTML support with links and form post backs. The 2.x branch is adding CSS Selectors into JSON, JSON Link support for Links based on URI Templates, and soon JSON Actions with support for forms. Today, the code is functional with automated tests, but the documentation is sparse. We especially need some tutorials. See the forum and GitHub for more details.

14 thoughts on “Mechanize for Java

  1. Pingback: Announcing mechanize for java | Gist Labs

  2. Hi, I use Mechanize with Perl and I’m looking for a similar library to use it in Android (Java) apps. Glad I found your project!

    Many times I use in my scripts in Perl:
    $mech->post (…);
    Is there a possibility to do it with your library?

    Thanks in advance!


    • Hello Mat,

      Thanks for commenting, and the feature request.

      I’m sure we can expose post directly (and you are welcome to contribute a pull request on GitHub is you were inspired.)

      Are you thinking something like:, mapNameValueParams)


  3. Hi John,
    thanks for your answer.

    Exactly. In Perl it’s inherited from LWP::UserAgent. There we can do for example:

    my $response = $browser->post($url,
    [ ‘value1’=>”2″,
    ## etc.etc.etc….
    ], @ns_headers);

    Would be great to see it in your Java implementation.

  4. Dear,

    I’m trying to use mechanize, but I’ve problem with dependencies. NetBeans cannot find the following symbols in

    import org.apache.http.Header;
    import org.apache.http.HttpException;
    import org.apache.http.HttpResponseInterceptor;
    import org.apache.http.entity.BufferedHttpEntity;
    import org.apache.http.params.HttpProtocolParams;
    import org.apache.http.protocol.BasicHttpContext;

    import org.apache.http.Header;
    import org.apache.http.HttpMessage;

    import org.apache.http.Header;
    import org.apache.http.HeaderElement;
    import org.apache.http.HttpMessage;
    import org.apache.http.HttpResponse;
    import org.apache.http.entity.ByteArrayEntity;
    import org.apache.http.message.BasicHttpResponse;

    and others….

    NetBeans add the following libraries like dependencies:

    Can you help me to solve the problem?

    • hi enrico,
      where do you get “css-selector-1.0.4” ? can you offer me the link? i searched it from the google , but still not found it.

  5. hi, i try to test mechanize4j, but get the errors that can’t find below classes:

    import se.fishtank.css.selectors.NodeSelectorException;
    import se.fishtank.css.selectors.Selector;
    import se.fishtank.css.selectors.Specifier;
    import se.fishtank.css.selectors.scanner.Scanner;
    import se.fishtank.css.selectors.scanner.ScannerException;
    import se.fishtank.css.selectors.specifier.AttributeSpecifier;
    import se.fishtank.css.selectors.specifier.NegationSpecifier;
    import se.fishtank.css.selectors.specifier.PseudoClassSpecifier;
    import se.fishtank.css.selectors.specifier.PseudoNthSpecifier;
    import se.fishtank.css.util.Assert;

  6. Pingback: Ultimate List of All Scraping Tools Ever - Fixeded

Leave a Reply

Your email address will not be published. Required fields are marked *