使用Java在网页中的许多可能选择中选择一个
I want to get the HTML code of the following Web Page (http://www.studenti.ict.uniba.it/esse3/ListaAppelliOfferta.do) after:
我想在以下网址获取以下网页的HTML代码(http://www.studenti.ict.uniba.it/esse3/ListaAppelliOfferta.do):
- selecting "Dipartimento di Informatica" among Facoltà
- selecting "Informatica" (or one of the others available)
- clicking "Avvia Ricerca"
在Facoltà中选择“Dipartimento di Informatica”
选择“Informatica”(或其他可用的)
点击“Avvia Ricerca”
I am not very keen in the matter but I noticed the URL of the page stays the same after each selection!?!
我对此事并不是很热衷,但我注意到每次选择后页面的网址都保持不变!?!
Can anyone help describing, possibly in details, how can I do that? Unfortunately I am not expert in web programming.
任何人都可以帮助描述,可能在细节上,我该怎么做?不幸的是,我不是网络编程专家。
Many thanks
1 个解决方案
#1
1
After some tests, it refresh the pages with a POST request
经过一些测试后,它会使用POST请求刷新页面
fac_id:1012 --
cds_id:197 --
ad_id: -- Attività didattica
docente_id: -- Id of the docent selected
data:06/03/2014 -- Date
Anyway you missed the value of Attività ditattica
, Docente
and Data esame
无论如何,你错过了Attivitàditattica,Docente和Data esame的价值
Just run a HTTP request using HttpURLConnection
(?) with this POST args, and with a XML parser read the output of tplmessage table.
只需使用带有此POST参数的HttpURLConnection(?)运行HTTP请求,并使用XML解析器读取tplmessage表的输出。
Try this tutorial for HTTP request: click.
尝试本教程获取HTTP请求:单击。
Try to read this to understand how to parse response: click
尝试阅读本文以了解如何解析响应:单击
An example using the code of the tutorial:
使用本教程代码的示例:
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();
}
In response
you will have the DOM of the page.
作为回应,您将拥有该页面的DOM。
Anyway, use Chrome developers tool to get request args:
无论如何,使用Chrome开发人员工具来获取请求args:
更多相关文章
- TextView在单击时发送电子邮件
- Android 外部唤起应用跳转指定页面
- fragment保存页面不销毁
- Android欢迎页面自动跳转和触摸进入首页
- 通过ViewPager实现类似微信的页面切换(Fragment篇)
- android开发中如何从当前页面返回上一页面
- 在Webview上加载脱机更新页面
- 自定义BaseAdapter,在主Activity页面调用显示歌曲列表
- 提取Launcher中的WorkSapce,可以左右滑动切换屏幕页面的类