【问题标题】:Google Image request returns only 3 imagesGoogle 图片请求仅返回 3 张图片
【发布时间】:2014-05-12 13:24:51
【问题描述】:

我正在编写一个从 Google 图片请求图片的程序。

我得到一个 JSON 对象,我将其转换为数组。但由于某些原因,它总是只有 4 张图像,这听起来像是一个限制。我想禁用它...

JSONArray results = json.getJSONObject("responseData").getJSONArray("results");
for(int j = 0; j < results.length(); j++) {
    String strurl = results.getJSONObject(j).getString("unescapedUrl");
    BufferedImage image = null;
    try {

        URL url = new URI(strurl).toURL();
        System.out.println("URL content type:"+url.openConnection().getContentType());
        URLConnection connection = url.openConnection();
        image = ImageIO.read(connection.getInputStream());
        } catch(MalformedURLException e) {
        e.printStackTrace();
        } catch(IOException e ) {
        e.printStackTrace();
        continue;
        } catch (URISyntaxException e) {
        e.printStackTrace();
    }
    // I display the image.
}

无论搜索关键字是什么,JSONArray results 始终为 3(我打印出来)。

有没有办法定义我想要的结果数量?

我很绝望......我会很感激任何答案,即使是一个远射。

【问题讨论】:

    标签: java json google-image-search


    【解决方案1】:

    页面似乎只返回 4 张图片。所以我添加了start=number。因此我发送多个请求。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-01
      相关资源
      最近更新 更多