Home
> Uncategorized > Export Google Search Results to CSV
Export Google Search Results to CSV
I just wrote a handly function which uses the Google API to do a search, then export the results in CSV, for easy import into a database for further processing. Be aware, that this will probably max out your quota with one call, so be careful with it.
public void GoogleSearchToCSV(string SearchString, string FileName)
{
GoogleSearchService.GoogleSearchService gss =
new GoogleSearchService.GoogleSearchService(); string CSV = ""; try{
for(int i=170;i<10000;i+=10){
GoogleSearchService.GoogleSearchResult gsr = gss.doGoogleSearch("L3Pyyh5QFHKU740wXUu0/aBu17loGATB",SearchString,0,10,
false,"",false,"","",""); foreach(GoogleSearchService.ResultElement reSearch in gsr.resultElements){
CSV += reSearch.title.Replace(",","").Replace("n","") + ",";
CSV += reSearch.snippet.Replace(",","").Replace("n","") + ",";
CSV += reSearch.URL.Replace(",","").Replace("n","") + "n";
}
Debug.Write("Progress:" + i.ToString());
}
}
catch(Exception ex){
Debug.Write(ex.ToString());
}
FileStream fsOut =
new FileStream(FileName,FileMode.Create);StreamWriter swOut =
new StreamWriter(fsOut);swOut.Write(CSV);
fsOut.Close();
}
Categories: Uncategorized
Comments (0)
Trackbacks (0)
Leave a comment
Trackback