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>搜索项。

例如获取https://www.googleapis.com/customsearch/v1?键=插入您的密钥&cx=013036536707430787589:_pqjad5hr1a&q= flowers:pdf&alt=json

有关适用的其他参数,请访问 https://developers.google.com/custom-search/v1/using_rest

于 2012-11-14T06:40:07.400 回答