@Test
public void testunit(){
try{
WebClient wc = new WebClient(BrowserVersion.CHROME);
String publicId="ylzting";
String urlstr = "http://weixin.sogou.com/weixin?type=1&query=" + publicId + "&ie=utf8&sug=n&_sug_type_=";
/**HtmlUnit请求web页面*/
wc.getOptions().setJavaScriptEnabled(true); //启用JS解释器,默认为true
wc.getOptions().setCssEnabled(false); //禁用css支持
wc.getOptions().setThrowExceptionOnScriptError(false); //js运行错误时,是否抛出异常
wc.getOptions().setThrowExceptionOnFailingStatusCode(false);
wc.getOptions().setTimeout(8000); //设置连接超时时间 ,这里是10S。如果为0,则无限期
wc.setJavaScriptTimeout(5000);
HtmlPage page = wc.getPage(urlstr);
// String html=wc.getPage(urlstr).toString();
// Document doc=Jsoup.parse(html);
// List<Element> newsList=doc.getElementsByAttributeValue("class", "wx-rb bg-blue wx-rb_v1 _item");
// //获取公众号的链接
// String href=newsList.get(0).attr("href");
// System.out.println(href);
}catch(Exception e){
e.printStackTrace();
}
控制台输出如下
<http.wire> 00:05:14:770 DEBUG http-outgoing-0 << "[\r][\n]"
<http.wire> 00:05:14:770 DEBUG http-outgoing-0 << "28ca[\r][\n]"
<http.wire> 00:05:14:770 DEBUG http-outgoing-0 << "[0x1f][0x8b][0x8][0x0][0x0][0x0][0x0][0x0][0x0][0x3][0xbd]=k[0x8f][0xe3],,,,<background.JavaScriptExecutionJob> 00:05:15:338 DEBUG Executing JavaScript Execution Job 2: window.setTimeout(
function () {
t.wait(e, n, o);
}
, 100).
2 个解决方案
#1
自己顶一下,希望大神求助
#1
自己顶一下,希望大神求助
#2
java 类的,不应该发到
java 版去么,其下还有许多相应的小版呢