我目前正在使用 Java 获取文件中特定网页的源代码。
网页为:http://www.studenti.ict.uniba.it/esse3/ListaAppelliOfferta.do
我编写了一些代码来做到这一点:
try{
URL url= new URL("http://www.studenti.ict.uniba.it/esse3/ListaAppelliOfferta.do");
URLConnection urlConn = url.openConnection();
BufferedReader dis= new BufferedReader(new InputStreamReader((url.openStream())));
String s="";
while (( s=dis.readLine())!= null) {
System.out.println(s);
}
dis.close();
}catch (MalformedURLException mue) {}
catch (IOException ioe) {}
}
这很好用。
问题是我想“模拟”用户在 Facoltà 中选择“[1020] Dipartimento di Informatica”,并在 Corso di Studio 中选择“[1102] Informatica e Tecnologie per la produzione del Software”,然后用户单击“Avvia Ricerca”开始搜索并显示包含结果的表格。
目标是获取网页的源代码,其中还包含我需要的表中的信息。
我注意到,如果我手动进行这些选择,然后单击“Avvia Ricerca”开始搜索,则会再次加载网页,显示我需要的表中的数据,但 URL 不会更改。
因此,即使页面现在显示我需要的数据,在使用我的代码时,我也只能获取页面的源代码,因为它是在进行选择和搜索之前。
最佳答案
我之前曾使用 HTMLUnit ( http://htmlunit.sourceforge.net ) 做过类似的事情,对于模拟与网站有关的任何内容以及抓取效果非常好。
关于java - 模拟用户点击网页[JAVA],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22348920/