请有一个采用HtmlUnit去爬虫的例子给我下,为什么照网上的步骤去开发,但是还是报错呢?836669780@qq.com
在WebClientclient=newWebClient()这一句会抛以下异常?我的邮箱是836669780@qq.comExceptioninthread"main"...
在WebClient client = new WebClient()这一句会抛以下异常?我的邮箱是836669780@qq.com Exception in thread "main" java.lang.IllegalAccessError: class com.gargoylesoftware.htmlunit.javascript.regexp.HtmlUnitRegExpProxy$FixedSubString cannot access its superclass net.sourceforge.htmlunit.corejs.javascript.regexp.SubString
展开
1个回答
展开全部
import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlInput;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput;
import com.suntang.htmlUnit.crawlerTest.QuietCssErrorHandler;
import com.suntang.htmlUnit.crawlerTest.SilentIncorrectnessListener;
/**
* 登录测试
* @date 2014年4月4日
*/
public class LoginTest {
private static String testUrlString = "http://www.iteye.com/login";
private static String user_name = "yucang52555";//填用户名
private static String pass_word = "hongfeng123456";//密码
public static void main(String[] args) throws Exception {
WebClient webClient = new WebClient(BrowserVersion.CHROME);
webClient.getOptions().setCssEnabled(false);
webClient.getOptions().setJavaScriptEnabled(false);
webClient.setIncorrectnessListener(new SilentIncorrectnessListener());
webClient.setCssErrorHandler(new QuietCssErrorHandler());
HtmlPage page = webClient.getPage(testUrlString);
HtmlForm login_form = (HtmlForm)page.getElementById("login_form");
HtmlInput username_input = login_form.getInputByName("name");
username_input.click();
username_input.type(user_name);
HtmlInput password_input = login_form.getInputByName("password");
password_input.click();
password_input.type(pass_word);
HtmlSubmitInput login_button = (HtmlSubmitInput )page.getElementById("button");
HtmlPage result = login_button.click();
System.out.println(result.asXml());
}
}
已测试通过。
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlInput;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput;
import com.suntang.htmlUnit.crawlerTest.QuietCssErrorHandler;
import com.suntang.htmlUnit.crawlerTest.SilentIncorrectnessListener;
/**
* 登录测试
* @date 2014年4月4日
*/
public class LoginTest {
private static String testUrlString = "http://www.iteye.com/login";
private static String user_name = "yucang52555";//填用户名
private static String pass_word = "hongfeng123456";//密码
public static void main(String[] args) throws Exception {
WebClient webClient = new WebClient(BrowserVersion.CHROME);
webClient.getOptions().setCssEnabled(false);
webClient.getOptions().setJavaScriptEnabled(false);
webClient.setIncorrectnessListener(new SilentIncorrectnessListener());
webClient.setCssErrorHandler(new QuietCssErrorHandler());
HtmlPage page = webClient.getPage(testUrlString);
HtmlForm login_form = (HtmlForm)page.getElementById("login_form");
HtmlInput username_input = login_form.getInputByName("name");
username_input.click();
username_input.type(user_name);
HtmlInput password_input = login_form.getInputByName("password");
password_input.click();
password_input.type(pass_word);
HtmlSubmitInput login_button = (HtmlSubmitInput )page.getElementById("button");
HtmlPage result = login_button.click();
System.out.println(result.asXml());
}
}
已测试通过。
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询