0
votes

how to retrive data from google search result page and save that data #,

i have code to retrive the data from URL , but i cant retrive the data from google search result...

plz help me

code to retrive the data from URL

enter code here  URL iurl = new URL("https://www.google.co.in/search?q=Anirudhcreative%2Cprojects&sub=Submit+Query");
URLConnection urlconn = iurl.openConnection();

System.out.println("url connection>>:"+urlconn);

File f = new File("Ani 7 hindi gogole out put.html");  //************************************ file name ***

FileOutputStream fop = new FileOutputStream(f); BufferedReader br = new BufferedReader(new InputStreamReader(urlconn.getInputStream())); String line; //PrintWriter pw = respons int ii=0; String st=""; System.out.println("************* output of web page ***********"); while((line=br.readLine())!= null) {

System.out.println(""+line+"");
ii++;

st=">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"+ii;
System.out.println(">>>>>>>>>"+ii);
if(f.exists()){
fop.write(line.toString().getBytes());

//fop.write(st.toString().getBytes());

1
Welcome at SO. www.nic.in/hindi/projects is not google, so what do you mean? Please properly format your code.home

1 Answers

3
votes

Don't do that, use the Google JSON Search API if you want to retrieve data from the google search because it's easier to use this API than screen scraping.

Also look at the Terms and Conditions when using this API, maybe you are going to use this data for not allowed proposes.