根据几个组合框的选择,我需要取消this网站。 问题是没有API和URL是不变的,所以我不能复制url以匹配条件。没有API的第三方网站抓取
我管理,使用Firefox检查,找出post命令, 但在Java程序中使用它的时候这样:
String url = " https://gaiacrmkea.c-gaia.gr/city_thessaloniki/index.php";
URL obj = new URL(url);
HttpsURLConnection con = (HttpsURLConnection) obj.openConnection();
//add reuqest header
con.setRequestMethod("POST");
con.setRequestProperty("Accept-Language", "el-GR,el;q=0.8,en-US;q=0.5,en;q=0.3");
String urlParameters = "fyear=2015&esex=0&cdief=Όλες";
// Send post request
con.setDoOutput(true);
DataOutputStream wr = new DataOutputStream(con.getOutputStream());
wr.writeBytes(urlParameters);
wr.flush();
wr.close();
int responseCode = con.getResponseCode();
System.out.println("\nSending 'POST' request to URL : " + url);
System.out.println("Post parameters : " + urlParameters);
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+"\n");
}
in.close();
//print result
System.out.println(response.toString());
不起作用。它只返回图形和按钮,但没有真实的数据。 当我复制参数,并将其粘贴到Firefox,因此 https://gaiacrmkea.c-gaia.gr/city_thessaloniki/index.php?fyear=2015&esex=0&cdief=Όλες
我得到它恰到好处。
有什么想法?
编辑: 我希望能够每天自动完成。
编辑2: 已解决! 基于由ÖzhanDUZ提供的代码,我为了得到这三个组合框添加这些
Select type= document
.query("#esex")
.getSelect();
type.setSelectedIndex(1);
type.change();
Select dep =document
.query("#cdief")
.getSelect();
dep.setSelectedIndex(1);
dep.change();
。 现在我只需要做这个自动执行。
将尽快答复并回复you.thanks – 2015-04-03 15:00:53
这是一个伟大的提示!但我没有提到的是,我需要这个每天自动完成。我没有真的在我的问题中提到它,因为我认为它很容易被接受,但是对于你的COOL解决方案,我需要手动完成。任何其他想法? – 2015-04-03 20:08:44
当cookie用于跟踪状态时,进行自定义调用可能很乏味,视图状态存在;等等。即使在完美模仿时,在翻译过程中可能会很容易失去某些东西,并且观看页面错误的情况也会增加。 Ui4j,JavaFX和QT网络使用webkit和selenium,Ui4j同时使用wekit和chromium。 Ui4j没有硒的内存泄漏问题。很高兴看到它的功能超过了QTJambi或Selenium可以实现的功能。 – 2016-03-10 22:00:26