[英]How to use java to fill in a web page and pull back the results?
嘿,我对Java还是比较陌生,我正在尝试制作一个执行以下操作的应用程序:
例如,假定以下站点显示了游戏结果,其中“ game = 500”显示了500个不同游戏中第324个游戏的结果。 http://www.some-site.com/results.php?game=324
我想使用Java程序自动将game = 1循环到game = 500,发布到网站上并检索页面结果。
做这个的最好方式是什么? 谁能给我一个简单的例子? 如果我知道正确的Java“关键字”,我会在Google上搜索有关此概念的一些教程。
注意:相关目标网页是php
URL url;
InputStream is = null;
DataInputStream dis;
String line;
for(int i=1;i<=500;i++){
try {
url = new URL("http://www.some-site.com/results.php?game="+i);
is = url.openStream(); // throws an IOException
dis = new DataInputStream(new BufferedInputStream(is));
while ((line = dis.readLine()) != null) {
//do sth with the datea
}
} catch (MalformedURLException mue) {
mue.printStackTrace();
} catch (IOException ioe) {
ioe.printStackTrace();
} finally {
try {
is.close();
} catch (IOException ioe) {
// nothing to see here
}
}
}
在另一个stackoverflow页面中执行类似答案的操作
然后您要使用for循环遍历第1至500页。
Apache有一些非常好的Java库,用于访问HTTP。 请参阅此以获取更多详细信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.