21,458
社区成员
发帖
与我相关
我的任务
分享
@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();
}