예제 #1
0
        /// <summary>
        /// Perform a Google search and return the results. Only return
        /// 100 results.
        /// </summary>
        /// <param name="query">What to search for.</param>
        /// <returns>The URL's that google returned for the search.</returns>
        public static List <ResultElement> GetResults(String query)
        {
            List <ResultElement> result = new List <ResultElement>();
            int resultCount             = 0;
            int top = 0;

            do
            {
                GoogleSearchResult r = search.doGoogleSearch(key,
                                                             query, top, 10, false, "", false, "", "latin1", "latin1");
                resultCount = r.resultElements.GetLength(0);

                if (r != null)
                {
                    foreach (ResultElement element in r.resultElements)
                    {
                        result.Add(element);
                    }
                }
                top = top + 10;
                Console.WriteLine("Searching Google: " + top);
            } while ((resultCount >= 10) && (top < 100));

            return(result);
        }
예제 #2
0
        static void Main(string[] args)
        {
            string googleKey = "yWje5FlQFHIDjiuRQzVyhVmvn9dSjsPp";

            if( args.Length == 0 || (args.Length == 1 && (args[0] == "?" || args[0] == "/?" || args[0] == "-?" || args[0].ToLower() == "help")))
            {
                Console.WriteLine("Usage: google.exe <query>\n");
                return;
            }

            string query = args[0];

            // Create a Google SOAP client proxy, generated by:
            // c:\> wsdl.exe http://api.google.com/GoogleSearch.wsdl
            GoogleSearchService googleSearch = new GoogleSearchService();

            GoogleSearchResult results = googleSearch.doGoogleSearch(googleKey, query, 0, 10, false, "", false, "", "latin1", "latin1");

            if (results.resultElements != null)
            {
                foreach (ResultElement result in results.resultElements)
                {
                    Console.WriteLine();
                    Console.WriteLine(result.title.Replace("<b>", "").Replace("</b>", ""));
                    Console.WriteLine(result.URL);
                    //Console.WriteLine(result.snippet);
                    Console.WriteLine();
                }
            }
        }
예제 #3
0
    public void CallGoogleSearch(string toSearch)
    {
        GoogleSearchService Search  = null;
        GoogleSearchResult  Results = null;

        try
        {
            Search  = new GoogleSearchService();
            Results = Search.doGoogleSearch(
                "Vaš Licence Key",
                toSearch, 0, 10, false, "", false, "", "", "");
        }
        catch (System.Net.WebException e)
        {
            Console.WriteLine(e.Message);
            return;
        }

        Process IE = new Process();

        IE.StartInfo.FileName  = "iexplore.exe";
        IE.StartInfo.Arguments = Results.resultElements[0].URL;
        IE.Start();

        SaveToDisk(Results);
    }
예제 #4
0
        private void Search_Click(object sender, System.EventArgs e)
        {
            GoogleSearchService s = new GoogleSearchService();

            /*
             * s.doGoogleSearch(string license,string query, int start, int maxResults,
             * bool filter,string restrict,bool safeSearch, string lr, string ie, string oe)
             */

            try
            {
                int start = (Convert.ToInt32(TextBox2.Text) - 1) * 10;

                GoogleSearchResult r = s.doGoogleSearch(licKey, txtSearchString.Text, start, maxResults, false, string.Empty, false, string.Empty, string.Empty, string.Empty);

                // Extract the estimated number of results for the search and display it
                int estResults = r.estimatedTotalResultsCount;

                lblHits.Text = Convert.ToString(estResults) + " Results found";

                DataSet ds1 = new DataSet();
                DataSet ds  = FillGoogleDS(ds1, r);
                DataGrid1.DataSource = ds;
                DataGrid1.DataBind();
            }
            catch (Exception ex)
            {
                lblHits.Text = ex.Message;
                return;
            }

            return;
        }
예제 #5
0
        /// <summary>
        /// This is the main interface, which calls all of the
        /// helper methods.  We create the google objects, do the search, display the results inside
        /// this code.
        /// </summary>
        private void GoogleHandler()
        {
            // Create a Google Search object
            GoogleSearchService gss = new GoogleSearchService();

            // Invoke the search method
            GoogleSearchResult results = gss.doGoogleSearch(LICENSE_KEY, BuildQuery(),
                                                            0, 10, false, string.Empty, false, string.Empty, string.Empty, string.Empty);

            // Extract the estimated number of results for the search and display it
            lblResults.Text    = "Results Found: " + results.estimatedTotalResultsCount;
            lblResults.Visible = true;

            DataTable  table = new DataTable();
            DataColumn col1  = new DataColumn("Results", typeof(string));

            table.Columns.Add(col1);

            int pointer = 0;

            while (pointer < results.resultElements.Length)
            {
                DataRow row = table.NewRow();
                row[0] = FormatResults(results.resultElements[pointer]);
                table.Rows.Add(row);
                pointer++;
            }

            dgResults.DataSource = table;
            dgResults.DataBind();
        }
예제 #6
0
        static void Main(string[] args)
        {
            string googleKey = "yWje5FlQFHIDjiuRQzVyhVmvn9dSjsPp";


            if (args.Length == 0 || (args.Length == 1 && (args[0] == "?" || args[0] == "/?" || args[0] == "-?" || args[0].ToLower() == "help")))
            {
                Console.WriteLine("Usage: google.exe <query>\n");
                return;
            }

            string query = args[0];

            // Create a Google SOAP client proxy, generated by:
            // c:\> wsdl.exe http://api.google.com/GoogleSearch.wsdl
            GoogleSearchService googleSearch = new GoogleSearchService();

            GoogleSearchResult results = googleSearch.doGoogleSearch(googleKey, query, 0, 10, false, "", false, "", "latin1", "latin1");

            if (results.resultElements != null)
            {
                foreach (ResultElement result in results.resultElements)
                {
                    Console.WriteLine();
                    Console.WriteLine(result.title.Replace("<b>", "").Replace("</b>", ""));
                    Console.WriteLine(result.URL);
                    //Console.WriteLine(result.snippet);
                    Console.WriteLine();
                }
            }
        }
예제 #7
0
        /// <summary>
        /// Search button: do a search, display number of results
        /// </summary>
        private void searchButton_Click(object sender, System.EventArgs e)
        {
            // Create a Google Search object
            GoogleSearchService s = new GoogleSearchService();
            // Invoke the search method
            GoogleSearchResult r = s.doGoogleSearch(keyBox.Text, searchBox.Text,
                                                    0, 1, false, "", false, "", "", "");
            // Extract the estimated number of results for the search and display it
            int estResults = r.estimatedTotalResultsCount;

            searchResultLabel.Text = Convert.ToString(estResults);
        }
        /// <summary>
        /// Handles the Click event of the Search control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
        private void Search_Click(object sender, EventArgs e)
        {
            string searchText     = txtSearchString.Text;
            GoogleSearchService s = new GoogleSearchService();

            /*
             * s.doGoogleSearch(string license,string query, int start, int maxResults,
             * bool filter,string restrict,bool safeSearch, string lr, string ie, string oe)
             */

            try
            {
                //Overrides following
                if (restrictToThisDomain.Length != 0 && searchText.IndexOf("site:") == -1)
                {
                    searchText = searchText += " site:" + restrictToThisDomain.Trim();
                }

                if (searchThisSiteOnly && searchText.IndexOf("site:") == -1)
                {
                    searchText = searchText += " site:" + (Request.Url.Host);
                }

                //debug only
                //txtSearchString.Text = searchText;

                int start = (Convert.ToInt32(TextBox2.Text) - 1) * 10;

                GoogleSearchResult r = s.doGoogleSearch(licKey, searchText, start, maxResults, false, string.Empty, false, string.Empty, string.Empty, string.Empty);

                // Extract the estimated number of results for the search and display it
                int estResults = r.estimatedTotalResultsCount;

                lblHits.Text = Convert.ToString(estResults) + " Results found";

                DataSet ds1 = new DataSet();
                DataSet ds  = FillGoogleDS(ds1, r);
                DataGrid1.DataSource = ds;
                DataGrid1.DataBind();
            }
            catch (Exception ex)
            {
                lblHits.Text = ex.Message;
                return;
            }

            return;
        }
예제 #9
0
        public void DoQuery(Query query,
                            IQueryResult result,
                            IQueryableChangeData changeData)
        {
            StringBuilder sb = new StringBuilder();

            foreach (QueryPart part in query.Parts)
            {
                if (part is QueryPart_Human)
                {
                    sb.Append(((QueryPart_Human)part).QueryString);
                }
                else if (part is QueryPart_Text)
                {
                    sb.Append(((QueryPart_Text)part).Text);
                }
                else
                {
                    continue;                     // ignore other query parts
                }
            }

            Logger.Log.Debug("Querying google for '" + sb.ToString() + "'");
            GoogleSearchResult gsr = gss.doGoogleSearch(googleKey,
                                                        sb.ToString(),
                                                        0, maxResults,
                                                        false, "", false, "", "", "");

            ArrayList hits = new ArrayList();
            int       rank = 0;

            foreach (ResultElement elt in gsr.resultElements)
            {
                Hit hit = FromGoogleResultElement(elt, rank);
                hits.Add(hit);
                ++rank;
            }
            result.Add(hits, gsr.estimatedTotalResultsCount);
        }