private str_reshdr GetGoogleItems(String sz_http) { str_reshdr returnthingy = new str_reshdr(); // OK. Here's what we do... // We get the index of the class="t bt" TABLE-TAG. // We then look for the end of the TABLE, and create a substring. // This contains the result header items (results x to y of z) etc. int n_reshdr = sz_http.IndexOf("<td align=right nowrap>", StringComparison.OrdinalIgnoreCase); if (n_reshdr > 0) { String sz_hdrresonly = sz_http.Substring(n_reshdr, sz_http.Length - n_reshdr); int n_hdrtab = sz_hdrresonly.IndexOf("</table>", StringComparison.OrdinalIgnoreCase); if (n_hdrtab > 0) { String TheHeader = sz_hdrresonly.Substring(0, sz_hdrresonly.Length - n_hdrtab); int n_Total = this.GoogleParseTotals(TheHeader); returnthingy.n_total = n_Total; // OK. Now, we have the total. We need the results... // We look for the index of the first <div class=g item. This is the first link result... int n_detitm = sz_hdrresonly.IndexOf("<div class=g", StringComparison.OrdinalIgnoreCase); if (n_detitm > 0) { String sz_resonly = sz_hdrresonly.Substring(n_detitm, sz_hdrresonly.Length - n_detitm); sz_resonly = sz_resonly.Replace("\r", ""); sz_resonly = sz_resonly.Replace("\n", ""); ArrayList tmpres = GoogleParseItems(sz_resonly); returnthingy.res_itm = tmpres; } else { returnthingy.n_total = 0; returnthingy.res_itm = new ArrayList(); } } else { returnthingy.n_total = 0; returnthingy.res_itm = new ArrayList(); } } else { returnthingy.n_total = 0; returnthingy.res_itm = new ArrayList(); } return(returnthingy); }
private StructuredEngineResult GoogleSearch() { //System.Diagnostics.Debug.WriteLine("Houston, We're running in the Google Search Routine"); StructuredEngineResult return_item = new StructuredEngineResult(); String GoogleHtml = this.GetGooglePage(); if (GoogleHtml.StartsWith("ERROR:")) { StructuredResultElement sre = new StructuredResultElement("Google", "", "", "", "", "", GoogleHtml); return_item.ResultItems.Add(sre); } else { str_reshdr outres = GetGoogleItems(GoogleHtml); return_item.ResultSource = "Google"; return_item.ResultTotal = outres.n_total; foreach (str_resitm the_itm in outres.res_itm) { StructuredResultElement sre = new StructuredResultElement("Google", the_itm.sz_url, the_itm.sz_cache, the_itm.sz_snip, the_itm.sz_snip, the_itm.sz_title, "SUCCESS"); return_item.ResultItems.Add(sre); } } return(return_item); }
private str_reshdr GetGoogleItems(String sz_http) { str_reshdr returnthingy = new str_reshdr(); // OK. Here's what we do... // We get the index of the class="t bt" TABLE-TAG. // We then look for the end of the TABLE, and create a substring. // This contains the result header items (results x to y of z) etc. int n_reshdr = sz_http.IndexOf("<td align=right nowrap>", StringComparison.OrdinalIgnoreCase); if (n_reshdr > 0) { String sz_hdrresonly = sz_http.Substring(n_reshdr, sz_http.Length - n_reshdr); int n_hdrtab = sz_hdrresonly.IndexOf("</table>", StringComparison.OrdinalIgnoreCase); if (n_hdrtab > 0) { String TheHeader = sz_hdrresonly.Substring(0, sz_hdrresonly.Length - n_hdrtab); int n_Total = this.GoogleParseTotals(TheHeader); returnthingy.n_total = n_Total; // OK. Now, we have the total. We need the results... // We look for the index of the first <div class=g item. This is the first link result... int n_detitm = sz_hdrresonly.IndexOf("<div class=g", StringComparison.OrdinalIgnoreCase); if (n_detitm > 0) { String sz_resonly = sz_hdrresonly.Substring(n_detitm, sz_hdrresonly.Length - n_detitm); sz_resonly = sz_resonly.Replace("\r", ""); sz_resonly = sz_resonly.Replace("\n", ""); ArrayList tmpres = GoogleParseItems(sz_resonly); returnthingy.res_itm = tmpres; } else { returnthingy.n_total = 0; returnthingy.res_itm = new ArrayList(); } } else { returnthingy.n_total = 0; returnthingy.res_itm = new ArrayList(); } } else { returnthingy.n_total = 0; returnthingy.res_itm = new ArrayList(); } return returnthingy; }