Java - 获取Web内容,跳过中间页面以响应达到所需的响应

时间:2012-12-26 19:23:35

标签: java web-crawler web-content

爪哇 我有必须在表单提交的结果中获取响应的Web内容的情况,但是它有点棘手b / s流程不像请求和响应那么简单,如下所示。

Submit button pressed -> Display page processing wait timer -> Display quick advertisement page -> Display page result.

从“按下提交按钮”开始,我希望“显示页面结果”内容并跳过两者之间的页面。

我有这个示例代码,但它只能以一种方式工作,发送请求和接收响应。

URL url;
InputStream is = null;
DataInputStream dis;
String line;

try {
    url = new URL("http://stackoverflow.com/");
    is = url.openStream();  // throws an IOException
    dis = new DataInputStream(new BufferedInputStream(is));

    while ((line = dis.readLine()) != null) {
        System.out.println(line);
    }
} catch (MalformedURLException mue) {
     mue.printStackTrace();
} catch (IOException ioe) {
     ioe.printStackTrace();
} finally {
    try {
        is.close();
    } catch (IOException ioe) {
        // nothing to see here
    }
}

任何java库都能为我做到吗?提前谢谢。

1 个答案:

答案 0 :(得分:1)

考虑尝试Selenium web driver。可能它有你想要实现的东西。