簡體   English   中英

通過http請求java獲取iframe內容

[英]Get iframe content by http request java

伙計們!

我正在嘗試使用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方法,但無論如何都不行。 有沒有辦法獲得這些內容?

謝謝。

是。 您需要請求iframe的網址,而不是原始網頁的網址。 如果您不知道iframe的URL或者它是否可以動態更改,則需要解析原始頁面的HTML並提取iframe URL。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM