【问题标题】:Get iframe content by http request java通过http请求java获取iframe内容
【发布时间】:2015-03-03 19:39:28
【问题描述】:

伙计们!

我正在尝试使用 java HTTP 请求获取 iframe 的内容。 我的代码工作正常,但它没有给我带来 iframe 内容,只是 HTML 页面的主要代码。

页面包含一个 iframe id“iframeContent”,但响应没有带来 iframe 内容,只是他在页面上的声明。

我正在使用这个:

        URL obj = new URL(url);
    HttpURLConnection con = (HttpURLConnection) obj.openConnection();

    // optional default is GET
    con.setRequestMethod("GET");

    //add request header
    con.setRequestProperty("User-Agent", USER_AGENT);

    int responseCode = con.getResponseCode();
    System.out.println("\nSending 'GET' request to URL : " + url);
    System.out.println("Response Code : " + responseCode);

    BufferedReader in = new BufferedReader(
            new InputStreamReader(con.getInputStream()));
    String inputLine;
    StringBuffer response = new StringBuffer();

    while ((inputLine = in.readLine()) != null) {
        response.append(inputLine);
    }
    in.close();

    //print result
    System.out.println(response.toString());

我也尝试过使用 POST 方法,但无论如何都不起作用。 有什么方法可以获取该内容吗?

谢谢。

【问题讨论】:

    标签: java http iframe request httprequest


    【解决方案1】:

    是的。您需要请求 iframe 的 URL,而不是原始页面的 URL。如果不知道 iframe 的 URL 或者它可以动态变化,则需要解析原始页面的 HTML 并提取 iframe 的 URL。

    【讨论】:

    • 我知道 iframe 的名称,但是如何传递包含 iframe 的 URL?之后,我想在 iframe 中获取 jCaptcha 图像,并将其显示在我的应用程序上。 PS:无法直接访问iframe,需要通过主页面。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-29
    • 2019-02-15
    • 1970-01-01
    • 1970-01-01
    • 2013-04-06
    • 2020-03-26
    相关资源
    最近更新 更多