如何使用java来填写网页和拉回结果


How to use java to fill in a web page and pull back the results?

嘿,我是java的新手,我想做一个应用程序,做以下事情:

  1. 发送请求到一个正在运行的网站
  2. 检索该页面的数据

例如,假设以下网站显示游戏结果,其中'game=500'显示500个不同游戏中第324个游戏的结果。http://www.some-site.com/results.php?game=324

我想使用一个Java程序来自动循环通过game=1到game=500,张贴到网站和检索页面的结果。

最好的方法是什么?谁能给我举个简单的例子?如果我知道正确的java"关键词",我就会谷歌一些关于这个概念的教程。

注意:这里的目标页面是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页面中执行类似的操作

然后在第1页到第500页使用for循环

Apache有一些非常好的Java库来访问HTTP。