java - 使用 Java 在网页中的众多可能选项中选择一个

标签 java html

我想获取以下网页( http://www.studenti.ict.uniba.it/esse3/ListaAppelliOfferta.do )的 HTML 代码:

  1. 在 Facoltà 中选择“Dipartimento di Informatica”
  2. 选择“Informatica”(或其他可用选项之一)
  3. 点击“Avvia Ricerca”

我对此事不太感兴趣,但我注意到每次选择后页面的 URL 都保持不变!?!

任何人都可以帮助描述(可能是详细的)我该怎么做吗?不幸的是我不是网络编程方面的专家。

非常感谢

最佳答案

经过一些测试,它通过 POST 请求刷新页面

fac_id:1012 --
cds_id:197  -- 
ad_id: -- Attività didattica
docente_id:  -- Id of the docent selected
data:06/03/2014 -- Date

无论如何,您错过了 Attività ditatticaDocenteData esame 的值(value)

只需使用 HttpURLConnection 运行 HTTP 请求(?) 使用此 POST 参数,并使用 XML 解析器读取 tplmessage 表的输出。

尝试使用本教程来处理 HTTP 请求:click .

尝试阅读此内容以了解如何解析响应:click

<小时/>

使用教程代码的示例:

HttpURLConnection connection = null;
try
{
    URL url = new URL("http://www.studenti.ict.uniba.it/esse3/ListaAppelliOfferta.do");
    connection = (HttpURLConnection) url.openConnection(); // open the connection with the url

    String params =
            "fac_id=1012&cds_id=197"; // You need to add ad_id, docente_id and data

    connection.setRequestMethod("POST"); // i need to use POST request method
    connection.setRequestProperty("Content-Length", "" + Integer.toString(params.getBytes().length)); // It will add the length of params

    connection.setRequestProperty("Content-Language", "it-IT"); // language italian

    connection.setUseCaches (false);
    connection.setDoInput   (true);
    connection.setDoOutput  (true);

    DataOutputStream wr = new DataOutputStream(
            connection.getOutputStream ());
    wr.writeBytes (params); // pass params
    wr.flush (); // send request
    wr.close ();

    //Get Response
    InputStream is = connection.getInputStream();
    BufferedReader rd = new BufferedReader(new InputStreamReader(is));
    String line;
    StringBuilder response = new StringBuilder();
    while((line = rd.readLine()) != null) {
        response.append(line);
        response.append('\r');
    }
    rd.close();
}
catch (MalformedURLException e)
{
    e.printStackTrace();
} catch (IOException e)
{
    e.printStackTrace();
}
finally
{
    // close connection if created
    if (connection != null)
        connection.disconnect();
}

response 中,您将获得页面的 DOM。

<小时/>

无论如何,使用 Chrome 开发者工具来获取请求参数:

aw

关于java - 使用 Java 在网页中的众多可能选项中选择一个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22441565/

相关文章:

java - S3 : Generating Pre-Signed URL for a given Key. [ key 可能/不存在]

java - 一个递归回溯问题

java - 前进 ListView 下一项/setSelectionFromTop 不起作用/禁止用户滚动 ListView

html - Woocommerce 页脚未与全屏对齐

java - Bitmap.compress 导致文件太大

Java 相当于 C# DESCrypto

javascript - 使用 javascript 或 jQuery 将 <a> 标签分配给 div

Javascript 检查页面上所有 <span> 标签 ID

html - xpath获取以特定字符或字符串开头的数据

javascript - 为什么当我使用 Javascript 绝对定位某些东西时,它的 "left"和 "top"属性总是变为 0px?