簡體   English   中英

谷歌自定義圖片搜索 - 只返回網站圖片

[英]Google custom image search - only returns website images

我想使用 Google 自定義搜索 API 獲取一些 Google 圖片。 但我得到的不是谷歌圖片,而是網站的縮略圖。 這里有一個例子:

我正在獲取這些縮略圖的鏈接: 在此處輸入圖片說明

但我想要這些圖片的鏈接: 在此處輸入圖片說明

也許 somoene 可以告訴我怎么做!

編碼:

public static void main(String[] args) throws Exception {

    String key = "";
    String cx = "";
    String keyword = "coke";

    URL url = new URL("https://www.googleapis.com/customsearch/v1?key=" + key + "&cx=" + cx + "&q=" + keyword);
    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    conn.addRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)");

    BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream())));

    String output;
    System.out.println("Output from Server .... \n");


    while ((output = br.readLine()) != null) {

        if((output.contains("jpg") || output.contains("png")) && output.contains("src")){                
            System.out.println(output);       //Will print the google search links
        }   
    }
    conn.disconnect();                              
   }

非常感謝!

您沒有指定要從 Google 進行圖片搜索。 您只是在正常結果中搜索可能的圖像。 您需要添加searchType=image

檢查此問題在此處了解有關查詢的更多信息。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM