2013-10-26 41 views
0

我不知道如何解决这个问题... 请问你能帮我吗?Java:创建webclient/htmlunit例外

我得到这个exeption:Exception in thread "main" java.lang.NoClassDefFoundError: etc.

我的代码是:

package mainsrc; 

进口com.gargoylesoftware.htmlunit.WebClient;

public void search() throws Exception { 

WebClient wb = new WebClient(); }

+0

你看着什么通常会导致一个'的java .lang.NoClassDefFoundError'? –

+0

是的,但我仍然无法弄清楚什么是错的。不是专业人士。 – Curratos

+0

您尚未正确设置HTMLUnit。检查这个问题[如何在Eclipse项目中设置HtmlUnit?](http://stackoverflow.com/questions/9096433/how-to-setup-htmlunit-in-an-eclipse-project) –

回答

0

我想你应该更好地使用selenium-firefox-driver-2.0a5.jar并且像下面的代码片段一样模仿Firefox浏览器。你也可以使用chrome。

使用下面的进口,并选择网络浏览器 ,此外你必须使用硒的服务器独立-2.44.0.jar以上版本

import com.gargoylesoftware.htmlunit.WebClient;//you already use this 
import com.gargoylesoftware.htmlunit.BrowserVersion; 
import com.gargoylesoftware.htmlunit.html.*; 

WebClient webClient = new WebClient(BrowserVersion.FIREFOX_24); 
HtmlPage page = (HtmlPage) webClient.getPage("Page url");