Question

I've been experiencing problems with the following source code:

import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.NicelyResynchronizingAjaxController;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.WebRequest;
import com.gargoylesoftware.htmlunit.html.HtmlPage;

import java.net.URL;

/**
 * Created by Boris on 14-1-2.
 */
public class Parser {

    public static void main(String[] args) throws Exception {

        WebClient webClient = new WebClient(BrowserVersion.FIREFOX_17);
        webClient.setAjaxController(new NicelyResynchronizingAjaxController());

        WebRequest request = new WebRequest(new URL("http://oddsportal.com"));
        HtmlPage page = webClient.getPage(request);

        int i = webClient.waitForBackgroundJavaScript(1000);

        while (i > 0)
        {
            i = webClient.waitForBackgroundJavaScript(1000);

            if (i == 0)
            {
                break;
            }
            synchronized (page)
            {
                System.out.println("wait");
                page.wait(500);
            }
        }

        webClient.getAjaxController().processSynchron(page, request, false);

        System.out.println(page.asXml());

    }
}

This is the error message:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/pool/ConnPoolControl
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:792)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at com.gargoylesoftware.htmlunit.HttpWebConnection.createHttpClient(HttpWebConnection.java:557)
    at com.gargoylesoftware.htmlunit.HttpWebConnection.getHttpClient(HttpWebConnection.java:518)
    at com.gargoylesoftware.htmlunit.HttpWebConnection.getResponse(HttpWebConnection.java:155)
    at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseFromWebConnection(WebClient.java:1486)
    at com.gargoylesoftware.htmlunit.WebClient.loadWebResponse(WebClient.java:1403)
    at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:305)
    at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:390)
    at DIIParser.Parser.main(Parser.java:22)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: java.lang.ClassNotFoundException: org.apache.http.pool.ConnPoolControl
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 25 more

I read a lot about the topic, included browser version to WebClient, switched to the old version 4.2 of org.apache.httpcomponents, tried casting HtmlPage as stated in another topic here but nothing helps. All I want is to load a particular page and wait until the javascript is executed, after that parse it with jsoup. Thank you in advance for your help!

Regards, Boris

Was it helpful?

Solution

Although you haven't explained what you have done so far to get that error I guess you haven't imported the appropriate libraries. Make sure you import all the libraries that come in the HTMLUnit distribution.

You can take a look at how to do this in Eclipse in the following question, maybe it can help: How to setup HtmlUnit in an Eclipse project?

By the way, there is no need to switch to any old version. Just import the libraries and you're done.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top