public static string Translate(string fromLang, string toLang, string query) { // BingService implements IDisposable. using (BingService service = new BingService()) { try { SearchRequest request = BuildRequest(fromLang, toLang, query); // Send the request; display the response. SearchResponse response = service.Search(request); return(ParseTranslation(response)); } catch (System.Web.Services.Protocols.SoapException ex) { // A SOAP Exception was thrown. Display error details. DisplayErrors(ex.Detail); } catch (System.Net.WebException ex) { // An exception occurred while accessing the network. Console.WriteLine(ex.Message); } } return("|ERROR - no translation"); }
private List <Link> procuraBing(string query, uint nLinks, bool flagTodosTermos) { List <Link> list = new List <Link>(); BingService service = new BingService(); SearchRequest request = new SearchRequest(); // Usar a AppID do Bing request.AppId = "FC90D229624ED0C50F60665F288516BD9FF1F40A"; request.Query = query; //Conteudo Adulto Off request.Adult = AdultOption.Off; request.AdultSpecified = true; // Pesquisar fontes na web request.Sources = new SourceType[] { SourceType.Web }; //Limitar numero de links request.Web = new WebRequest(); request.Web.Count = nLinks; request.Web.CountSpecified = true; SearchResponse response = service.Search(request); foreach (WebResult result in response.Web.Results) { list.Add(new Link(result.Title, result.Url, result.Description)); } return(list); }
public string Translate(string src, Language src_lang, Language dest_lang) { String result = null; BingService bs = new BingService(); SearchRequest sr = new SearchRequest(); sr.AppId = _apikey; sr.Sources = new SourceType[] { SourceType.Translation }; sr.Translation = new TranslationRequest(); sr.Translation.SourceLanguage = LangToString(src_lang); sr.Translation.TargetLanguage = LangToString(dest_lang); sr.Query = src; sr.Version = "2.2"; src = Unformat(src); SearchResponse response = bs.Search(sr); if (response != null) { if (response.Translation != null) { if (response.Translation.Results != null) { if (response.Translation.Results.Length > 0) { result = response.Translation.Results[0].TranslatedTerm; if (result.CompareTo(src) == 0) { result = null; } else if (result.Length == 0) { result = null; } } } } } if (result != null) { result = Format(result); } return(result); }
public void TestMultipleTermsCase() { BingService service = new BingService(); string searchCriteria = "internet information server"; SearchEngineQuery result; try { System.Threading.Thread.Sleep(2000); result = service.Search(searchCriteria).GetAwaiter().GetResult(); Assert.IsTrue(result != null && result.TotalResults > 0); } catch (Exception) { Assert.Fail("Exception was thrown"); } }
public void TestOneTermCase() { BingService service_one = new BingService(); string searchCriteria_one = "kubernetes"; SearchEngineQuery result_one; try { System.Threading.Thread.Sleep(2000); result_one = service_one.Search(searchCriteria_one).GetAwaiter().GetResult(); Assert.IsTrue(result_one != null && result_one.TotalResults > 0); } catch (Exception ex) { Assert.Fail("Exception was thrown" + ex.Message); } }
public void TestEmptyCriteriaCase() { BingService service = new BingService(); string searchCriteria = " "; SearchEngineQuery result; try { result = service.Search(searchCriteria).GetAwaiter().GetResult(); } catch (Exception ex) { StringAssert.Contains(ex.Message, "Search criteria is empty or null"); return; } Assert.Fail("Exception was not thrown"); }
public static string Translate(string sourceLanguageCode, string targetLanguageCode, string text) { using (BingService service = new BingService()) { try { SearchRequest request = BuildRequest(text, sourceLanguageCode, targetLanguageCode); // Send the request; display the response. SearchResponse response = service.Search(request); return(Response(response)); } catch (System.Web.Services.Protocols.SoapException) { // A SOAP Exception was thrown. Display error details. return(null); } catch (System.Net.WebException) { // An exception occurred while accessing the network. return(null); } } }
/// <summary> /// Searches Bing.com API /// </summary> /// <param name="query">The QueryString to search against</param> /// <param name="urlmatch">Only return URLs containing the following match</param> /// <param name="threadID">The thread MovieUniqueId.</param> /// <returns>First successful match.</returns> public static BindingList <QueryResult> SearchBing(string query, string urlmatch, int threadID, string regexTitle, string regexYear, string regexID, ScraperList scraperList) { var logCatagory = "Scrape > Bing Search > " + query; try { var queryResults = new BindingList <QueryResult>(); query = query.Replace("%20", " "); using (var service = new BingService()) { var searchRequest = new SearchRequest { Query = query, Sources = new[] { SourceType.Web }, AppId = "9A2F2F47CF77629DA4E35E912F4B696217DCFC3C" }; var webRequest = new WebRequest { Count = 10, Offset = 0, OffsetSpecified = true }; searchRequest.Web = webRequest; var response = service.Search(searchRequest); if (response.Web.Results != null) { foreach (var result in response.Web.Results) { if (string.IsNullOrEmpty(result.Url) || result.Url.Contains(urlmatch)) { var queryResult = new QueryResult(); if (Regex.IsMatch(result.Title, regexTitle)) { if (Regex.IsMatch(result.Url, regexID)) { switch (scraperList) { case ScraperList.Imdb: queryResult.ImdbID = Regex.Match(result.Url, regexID).Groups["id"].Value; break; case ScraperList.TheMovieDB: queryResult.TmdbID = Regex.Match(result.Url, regexID).Groups["id"].Value; break; case ScraperList.Allocine: queryResult.AllocineId = Regex.Match(result.Url, regexID).Groups["id"].Value; break; case ScraperList.FilmAffinity: queryResult.FilmAffinityId = Regex.Match(result.Url, regexID).Groups["id"].Value; break; case ScraperList.FilmDelta: queryResult.FilmDeltaId = Regex.Match(result.Url, regexID).Groups["id"].Value; break; case ScraperList.FilmUp: queryResult.FilmUpId = Regex.Match(result.Url, regexID).Groups["id"].Value; break; case ScraperList.FilmWeb: queryResult.FilmWebId = Regex.Match(result.Url, regexID).Groups["id"].Value; break; case ScraperList.Impawards: queryResult.ImpawardsId = Regex.Match(result.Url, regexID).Groups["id"].Value; break; case ScraperList.Kinopoisk: queryResult.KinopoiskId = Regex.Match(result.Url, regexID).Groups["id"].Value; break; case ScraperList.OFDB: queryResult.OfdbId = Regex.Match(result.Url, regexID).Groups["id"].Value; break; case ScraperList.MovieMeter: queryResult.MovieMeterId = Regex.Match(result.Url, regexID).Groups["id"].Value; break; case ScraperList.Sratim: queryResult.SratimId = Regex.Match(result.Url, regexID).Groups["id"].Value; break; } } queryResult.Title = Regex.Match(result.Title, regexTitle).Groups["title"].Value; queryResult.Year = Regex.Match(result.Title, regexYear).Groups["year"].Value.ToInt(); } else { queryResult.Title = result.Title; } queryResult.AdditionalInfo = result.Description; queryResult.URL = result.Url; queryResults.Add(queryResult); } } } Log.WriteToLog(LogSeverity.Info, 0, string.Format("Bing search complete ({0} results)", queryResults.Count), query); return(queryResults); } } catch (Exception ex) { Log.WriteToLog(LogSeverity.Error, LoggerName.GeneralLog, logCatagory, ex.Message); return(null); } }
private List<Link> procuraBing(string query, uint nLinks, bool flagTodosTermos) { List<Link> list = new List<Link>(); BingService service = new BingService(); SearchRequest request = new SearchRequest(); // Usar a AppID do Bing request.AppId = "FC90D229624ED0C50F60665F288516BD9FF1F40A"; request.Query = query; //Conteudo Adulto Off request.Adult = AdultOption.Off; request.AdultSpecified = true; // Pesquisar fontes na web request.Sources = new SourceType[] { SourceType.Web }; //Limitar numero de links request.Web = new WebRequest(); request.Web.Count = nLinks; request.Web.CountSpecified = true; SearchResponse response = service.Search(request); foreach (WebResult result in response.Web.Results) { list.Add(new Link(result.Title, result.Url, result.Description)); } return list; }