0

Here's some code I found on 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();                              
}

My question is: how do I restrict the search using filetype:pdf ?

bool.dev
  • 17,508
  • 5
  • 69
  • 93
Monica
  • 389
  • 1
  • 7
  • 19

1 Answers1

0

Use :<file-extension in the query> of the search item.

For example GET https://www.googleapis.com/customsearch/v1? key=INSERT-YOUR-KEY&cx=013036536707430787589:_pqjad5hr1a&q=flowers:pdf&alt=json

For other parameters applicable visit https://developers.google.com/custom-search/v1/using_rest

AurA
  • 12,135
  • 7
  • 46
  • 63
  • Thanks for the answer. Only that the search results do not contain only pdf files. I shall check the link you mention in your message. – Monica Nov 14 '12 at 21:16
  • for a trial you can search anything on google with :pdf (that will give only the pdf files) – AurA Nov 15 '12 at 04:37
  • Using the query q=resume:pdf I get results which contain also non-pdf files Output from Server .... http://nw01.american.edu/~ad4423a/resume08.pdf http://www.cornonthejob.com/career-advice/resumes-and-cover-letters/why-your-pretty-pdf-resume-might-be-killing-you/ http://www.dol.gov/vets/tap/F-TAPSupplement-CreateanEffectiveResume8.9.07.pdf http://life.umt.edu/career/PDF/resumexyz.pdf http://jobsearch.about.com/od/jobsearchemail/f/how-to-send-resume.htm http://www.drake.edu/career/student/pdf/resume.pdf http://my.fit.edu/ncsbiprojects/Resume.pdf – Monica Nov 19 '12 at 21:55
  • In most of the cases ... they will give you proper output http://support.google.com/webmasters/bin/answer.py?hl=en&answer=35287 but in case they don't you can filter the results by removing the links that (DOES NOT ENDS WITH) (.) – AurA Nov 20 '12 at 09:59