0

StackExchange で見つけたコードを次に示します。

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

String key="YOUR KEY";
String qry="Android";
URL url = new URL(
        "https://www.googleapis.com/customsearch/v1?key="+key+ "&cx=013036536707430787589:_pqjad5hr1a&q="+ qry + "&alt=json");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("Accept", "application/json");
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("\"link\": \"")){                
        String link=output.substring(output.indexOf("\"link\": \"")+("\"link\": \"").length(), output.indexOf("\","));
        System.out.println(link);       //Will print the google search links
    }     
}
conn.disconnect();                              
}

私の質問は: filetype:pdf を使用して検索を制限するにはどうすればよいですか?

4

1 に答える 1

0

:<file-extension in the query>検索項目の使用。

たとえば、GET https://www.googleapis.com/customsearch/v1 ? key=INSERT-YOUR-KEY&cx=013036536707430787589:_pqjad5hr1a&q= flowers:pdf&alt=json

適用可能なその他のパラメーターについては、 https://developers.google.com/custom-search/v1/using_restをご覧ください。

于 2012-11-14T06:40:07.400 に答える