日期:2014-05-20  浏览次数:20773 次

htmlunit运行错误
当运行到page = (HtmlPage) webClient.getPage(url);的时候不继续运行下一句代码而且也不停止;
我也设置了
webClient.getOptions().setCssEnabled(false);
webClient.getOptions().setJavaScriptEnabled(true);
webClient.getOptions().setThrowExceptionOnFailingStatusCode(false);
webClient.getOptions().setThrowExceptionOnScriptError(false);
webClient.setAjaxController(new NicelyResynchronizingAjaxController());

贴代码

public class TEST {
public static void main(String[] args) {
WebClient webClient=new WebClient(BrowserVersion.FIREFOX_17);
webClient.getOptions().setCssEnabled(false);
webClient.getOptions().setJavaScriptEnabled(true);
webClient.getOptions().setThrowExceptionOnFailingStatusCode(false);
webClient.getOptions().setThrowExceptionOnScriptError(false);
webClient.setAjaxController(new NicelyResynchronizingAjaxController());
HtmlPage page;
try { 
        // 构造一个URL   
        String url = new String("http://bwc.sanxiau.edu.cn");  
// 通过getPage()方法,返回相应的页面     
        page = (HtmlPage) webClient.getPage(url);
        //写入文件//
        List<HtmlAnchor> urlList = new ArrayList<HtmlAnchor>();
        
        urlList.addAll(page.getAnchors());
        Iterator<HtmlAnchor> it= urlList.iterator();
        //test
        String fileName = "D:\\Result2.txt";
        FileWriter fw = new FileWriter(new File(fileName),true);
        BufferedWriter bfw = new BufferedWriter(fw);
        while(it.hasNext()){
         HtmlAnchor ha = it.next();
        
        bfw.write(ha+"\n");
        }
        //test
        bfw.flush();
        fw.flush();
        bfw.close();
        fw.close();
        
        webClient.closeAllWindows();
} catch (FailingHttpStatusCodeException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

------解决方案--------------------
看看是否有断点。
------解决方案--------------------
http://bwc.sanxiau.edu.cn:8096/js/slidemenu/slidemenu.js#15

语法错误。你浏览器看看能不能直接访问这个
------解决方案--------------------
抓取的时候,转换没做好吧。设个断点看看