Esempio n. 1
0
        ///Method that return the number of Results of a Bing Search
        public static long?BingSearchResults(string searchTerm)
        {
            string searchURL      = "https://www.bing.com/search?q=" + Uri.EscapeDataString(searchTerm);
            string responseString = HttpAssistance.GetHTML(searchURL);

            //Filter and return result
            return(long.Parse(GetStringBetween(responseString, "<span class=\"sb_count\">", " ").Replace(".", "")));

            /*
             * //Pay api - Limited to 1000 search/month
             *  const string accessKey = "09f417ce9ae34ad3bcddbf0261187317";
             *  const string uriBase = "https://api.cognitive.microsoft.com/bing/v7.0/search?q={0}";
             *
             *  var request = WebRequest.Create(string.Format(uriBase, searchTerm));
             *  request.Headers["Ocp-Apim-Subscription-Key"] = accessKey;
             *
             *  HttpWebResponse response = (HttpWebResponse)request.GetResponseAsync().Result;
             *  Stream dataStream = response.GetResponseStream();
             *  StreamReader reader = new StreamReader(dataStream);
             *  string responseString = reader.ReadToEnd();
             *
             *  //No library allowed
             *  dynamic jsonData = JsonConvert.DeserializeObject(responseString);
             *  return jsonData.webPages.totalEstimatedMatches;
             */
        }
Esempio n. 2
0
        ///Method that return the number of Results of a Yahoo Search
        public static long?YahooSearchResults(string searchTerm)
        {
            string searchURL      = "https://search.yahoo.com/search?p=" + Uri.EscapeDataString(searchTerm);
            string responseString = HttpAssistance.GetHTML(searchURL);

            return(long.Parse(GetStringBetween(GetStringBetween(responseString, "<div class=\"compPagination\">", "</div>"), "<span>", " ").Replace(",", "")));
        }