static void Main(string[] args) { RNG = new Random(); var driver = new ChromeDriver(); driver.Manage().Timeouts().PageLoad = new TimeSpan(0, 0, 5); FIRSTTAB = driver.CurrentWindowHandle; for (int i = 0; i < 10; i++) { Google("latest news" + RandomSite(), driver); GoogleSearchResults results = new GoogleSearchResults(driver); GotoRandomSearchPage(results, driver); results = new GoogleSearchResults(driver); BrowseToRandomPage(results, driver); for (int j = 0; j < 10; j++) { BrowseToRandomPage(results, driver); } } }
private SearchResults PackageResults(GoogleSearchResults gsr, BingSearchResults bsr) { SearchResults results = new SearchResults(); foreach (SearchEngine.Model.Google.Item item in gsr.items) { SearchResult result = new SearchResult(); result.Name = item.title; result.DisplayUrl = item.formattedUrl; result.Url = item.formattedUrl; result.Snippet = item.snippet; result.Source = "Google"; results.SearchResultList.Add(result); } foreach (SearchEngine.Model.Bing.Value item in bsr.webPages.value) { SearchResult result = new SearchResult(); result.Name = item.name; result.DisplayUrl = item.displayUrl; result.Url = item.url; result.Snippet = item.snippet; result.Source = "Bing"; results.SearchResultList.Add(result); } results.SearchResultList = results.SearchResultList.OrderBy(x => x.Name).ToList(); return(results); }
public void SetUp() { Initialize(); _googleHomePage = new GoogleHome(Driver); _googleResultsPage = new GoogleSearchResults(Driver); _seleniumPage = new SeleniumPage(Driver); _googleHomePage.NavigateTo(); }
protected void Page_Load(object sender, EventArgs e) { GoogleSearchResults g1 = new GoogleSearchResults(); const string json = @"{""responseData"": {""results"":[{""GsearchResultClass"":""GwebSearch"",""unescapedUrl"":""http://www.cheese.com/"",""url"":""http://www.cheese.com/"",""visibleUrl"":""www.cheese.com"",""cacheUrl"":""http://www.google.com/search?q\u003dcache:bkg1gwNt8u4J:www.cheese.com"",""title"":""\u003cb\u003eCHEESE\u003c/b\u003e.COM - All about \u003cb\u003echeese\u003c/b\u003e!."",""titleNoFormatting"":""CHEESE.COM - All about cheese!."",""content"":""\u003cb\u003eCheese\u003c/b\u003e - everything you want to know about it. Search \u003cb\u003echeese\u003c/b\u003e by name, by types of milk, by textures and by countries.""},{""GsearchResultClass"":""GwebSearch"",""unescapedUrl"":""http://en.wikipedia.org/wiki/Cheese"",""url"":""http://en.wikipedia.org/wiki/Cheese"",""visibleUrl"":""en.wikipedia.org"",""cacheUrl"":""http://www.google.com/search?q\u003dcache:n9icdgMlCXIJ:en.wikipedia.org"",""title"":""\u003cb\u003eCheese\u003c/b\u003e - Wikipedia, the free encyclopedia"",""titleNoFormatting"":""Cheese - Wikipedia, the free encyclopedia"",""content"":""\u003cb\u003eCheese\u003c/b\u003e is a food consisting of proteins and fat from milk, usually the milk of cows, buffalo, goats, or sheep. It is produced by coagulation of the milk \u003cb\u003e...\u003c/b\u003e""},{""GsearchResultClass"":""GwebSearch"",""unescapedUrl"":""http://www.ilovecheese.com/"",""url"":""http://www.ilovecheese.com/"",""visibleUrl"":""www.ilovecheese.com"",""cacheUrl"":""http://www.google.com/search?q\u003dcache:GBhRR8ytMhQJ:www.ilovecheese.com"",""title"":""I Love \u003cb\u003eCheese\u003c/b\u003e!, Homepage"",""titleNoFormatting"":""I Love Cheese!, Homepage"",""content"":""The American Dairy Association\u0026#39;s official site includes recipes and information on nutrition and storage of \u003cb\u003echeese\u003c/b\u003e.""},{""GsearchResultClass"":""GwebSearch"",""unescapedUrl"":""http://www.gnome.org/projects/cheese/"",""url"":""http://www.gnome.org/projects/cheese/"",""visibleUrl"":""www.gnome.org"",""cacheUrl"":""http://www.google.com/search?q\u003dcache:jvfWnVcSFeQJ:www.gnome.org"",""title"":""\u003cb\u003eCheese\u003c/b\u003e"",""titleNoFormatting"":""Cheese"",""content"":""\u003cb\u003eCheese\u003c/b\u003e uses your webcam to take photos and videos, applies fancy special effects and lets you share the fun with others. It was written as part of Google\u0026#39;s \u003cb\u003e...\u003c/b\u003e""}],""cursor"":{""pages"":[{""start"":""0"",""label"":1},{""start"":""4"",""label"":2},{""start"":""8"",""label"":3},{""start"":""12"",""label"":4},{""start"":""16"",""label"":5},{""start"":""20"",""label"":6},{""start"":""24"",""label"":7},{""start"":""28"",""label"":8}],""estimatedResultCount"":""14400000"",""currentPageIndex"":0,""moreResultsUrl"":""http://www.google.com/search?oe\u003dutf8\u0026ie\u003dutf8\u0026source\u003duds\u0026start\u003d0\u0026hl\u003den-GB\u0026q\u003dcheese""}}, ""responseDetails"": null, ""responseStatus"": 200}"; g1 = JSONHelper.Deserialise <GoogleSearchResults>(json); foreach (Pages x in g1.responseData.cursor.pages) { // Anything you want to get Response.Write(x.label); } }
public async Task GoogleSearchTest() { DomainLogic dl = new DomainLogic(new ApiIntegrator()); GoogleSearchResults gsr = new GoogleSearchResults(); gsr = await dl.Search <GoogleSearchResults>("lambda" , "googleApiParameterConfig" , "googleApiHeaderConfig" , "googleApi"); Assert.IsTrue(gsr.items.Count > 0); }
public void ClassInitialize() { //RegistrationPages _driver = new ChromeDriver(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)); _wait = new WebDriverWait(_driver, TimeSpan.FromSeconds(30)); _driver.Manage().Window.Maximize(); _driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(30); _loginPage = new LoginPage(_driver); _registrationPageFull = new RegistrationPageFull(_driver); _user = UserFactory.CreateRegistrationUser(); //Google search _googleSearchPage = new GoogleSearchPage(_driver); _googleSearchResults = new GoogleSearchResults(_driver); _googleFindPage = new GoogleFindPage(_driver); //SoftUniCoursePage check _softUniCoursePage = new SoftUniCoursePage(_driver); _softUniPage = new SoftUniPage(_driver); }
public static void GotoRandomSearchPage(GoogleSearchResults results, IWebDriver driver) { bool clickSuccessful = false; while (!clickSuccessful) { List <IWebElement> otherPages = results.OtherSearchPages; IWebElement randomLink = otherPages[RNG.Next(otherPages.Count)]; try { Click(randomLink, driver); clickSuccessful = true; } catch (Exception e) { results = new GoogleSearchResults(driver); } } }
private async Task <SearchResults> Search(string searchTerm, string searchMode) { GoogleSearchResults gsr = new GoogleSearchResults(); BingSearchResults bsr = new BingSearchResults(); DomainLogic dl = new DomainLogic(new ApiIntegrator()); switch (searchMode) { case "all": gsr = await dl.Search <GoogleSearchResults>(searchTerm , "googleApiParameterConfig" , "googleApiHeaderConfig" , "googleApi"); bsr = await dl.Search <BingSearchResults>(searchTerm , "bingApiParameterConfig" , "bingApiHeaderConfig" , "bingApi"); break; case "google": gsr = await dl.Search <GoogleSearchResults>(searchTerm , "googleApiParameterConfig" , "googleApiHeaderConfig" , "googleApi"); break; case "bing": bsr = await dl.Search <BingSearchResults>(searchTerm , "bingApiParameterConfig" , "bingApiHeaderConfig" , "bingApi"); break; } return(PackageResults(gsr, bsr)); }
public static void BrowseToRandomPage(GoogleSearchResults results, IWebDriver driver) { bool clickSuccessful = false; while (!clickSuccessful) { results = new GoogleSearchResults(driver); List <IWebElement> googleSearchResults = results.SearchResults; List <IWebElement> otherLinks = GetAllLinks(driver); while (googleSearchResults.Count == 0 && otherLinks.Count == 0) { driver.Navigate().Back(); results = new GoogleSearchResults(driver); googleSearchResults = results.SearchResults; } IWebElement randomLink = otherLinks[RNG.Next(otherLinks.Count)]; if (googleSearchResults.Count > 0) { randomLink = googleSearchResults[RNG.Next(googleSearchResults.Count)]; } try { Click(randomLink, driver); clickSuccessful = true; } catch (Exception e) { results = new GoogleSearchResults(driver); } } }
private static async void TBot_OnMessage(object sender, Telegram.Bot.Args.MessageEventArgs messageEventArgs) { var message = messageEventArgs.Message; try { if (message == null || message.Type != MessageType.Text) { return; } Console.WriteLine("Chat ID: " + message.Chat.Id); Console.WriteLine(string.Format("Message from {0} {1} in chat {2}\nMessagee is: {3}", message.From.Username, message.From.Id, message.Chat.Title, message.Text)); if (chatBotEnabled) { bool isNormalchat = true; if (message.Text.StartsWith("!")) { isNormalchat = false; } if (isNormalchat) { try { if (message.Text.ToLower().Contains(botNick.ToLower())) { message.Text = Regex.Replace(message.Text.ToLower(), botNick.ToLower(), "ALICE", RegexOptions.IgnoreCase); } string botReply = chatBotSession.Think(message.Text); // lets mask the bot name shall we if (botReply.Contains("ALICE")) { botReply = Regex.Replace(botReply, "ALICE", botNick, RegexOptions.IgnoreCase); } await SendMsgToTelegram(message.Chat.Id, botReply); Console.WriteLine("chatBotReply to {0}: is {1}", message.Chat.Id, botReply); } catch (Exception ex) { Console.WriteLine(new ExceptionTBotChatBotReply(ex.Message)); await SendMsgToTelegram(message.Chat.Id, (new ExceptionTBotChatBotReply(ex.Message)).ToString()); } } } if (Regex.Match(message.Text.ToLower(), "!" + TBotCommand.HELP.ToString().ToLower()).Success&& listUsers.Exists(x => x.Username == message.From.Username && x.IsAdmin)) { ResourceSet helpResources = HelpResources.ResourceManager.GetResourceSet(CultureInfo.CurrentUICulture, true, true); StringBuilder helpMsg = new StringBuilder(); foreach (DictionaryEntry entry in helpResources) { helpMsg.AppendLine(string.Format(entry.Value.ToString() + Environment.NewLine)); } await SendMsgToTelegram(message.Chat.Id, helpMsg.ToString()); } else if (Regex.Match(message.Text.ToLower(), "!" + TBotCommand.CHATBOT.ToString().ToLower()).Success&& listUsers.Exists(x => x.Username == message.From.Username && x.IsAdmin)) { chatBotEnabled = !chatBotEnabled; if (chatBotEnabled) { await SendMsgToTelegram(message.Chat.Id, TBotStrings.EnabledChatBot); } else { await SendMsgToTelegram(message.Chat.Id, TBotStrings.DisabledChatbot); } } else if ((eval = Regex.Match(message.Text, "!" + TBotCommand.GOOGLE.ToString().ToLower() + "\\s{1,}(.{1,100})", RegexOptions.IgnoreCase)) != null && eval.Success) { string query = eval.Groups[1].ToString(); // se nos derem ping, dizemos isso e feio GoogleSearchResults result = await GoogleSearch(query); await SendMsgToTelegram(message.Chat.Id, "You have searched for: " + query); if (result != null) { await SendMsgToTelegram(message.Chat.Id, "Search time was: " + result.SearchTime); await SendMsgToTelegram(message.Chat.Id, "Total items found: " + result.TotalResults); if (result.Results.Count > 0) { foreach (var item in result.Results) { await SendMsgToTelegram(message.Chat.Id, "Title: " + item.Title); await SendMsgToTelegram(message.Chat.Id, "Link: " + item.Link); } } else if (result.Results.Count == 0 && result.TotalResults > 0) { await SendMsgToTelegram(message.Chat.Id, string.Format("Something not right, we have {0} search hits, but the list of results is empty", result.TotalResults)); } } } else if ((eval = Regex.Match(message.Text, "!" + TBotCommand.SQLGETUSERS.ToString().ToLower(), RegexOptions.IgnoreCase)) != null && eval.Success && listUsers.Exists(x => x.Username == message.From.Username && x.IsAdmin)) { listUsers = db.GetUserList(); foreach (TBotUser user in listUsers) { await SendMsgToTelegram(message.Chat.Id, string.Format(TBotStrings.TBotUsersChatMSG, user.ID, Environment.NewLine, user.Username, Environment.NewLine, user.IsAdmin.ToString())); } } else if ((eval = Regex.Match(message.Text, "!" + TBotCommand.SQLINSERTUSER.ToString().ToLower() + "\\s+(.*)\\s+(.*)", RegexOptions.IgnoreCase)) != null && eval.Success && listUsers.Exists(x => x.Username == message.From.Username && x.IsAdmin)) { string user = string.Empty; bool isAdmin = false; if (!string.IsNullOrEmpty(eval.Groups[1].ToString())) { user = eval.Groups[1].ToString(); } else { await SendMsgToTelegram(message.Chat.Id, TBotStrings.TBotNewUserParameterMising); return; } if (!string.IsNullOrEmpty(eval.Groups[2].ToString())) { if (eval.Groups[2].ToString().ToLower().Equals("true")) { isAdmin = true; } await SendMsgToTelegram(message.Chat.Id, string.Format(TBotStrings.TBotNewUserCreted, db.InsertUser(user, isAdmin))); } else { await SendMsgToTelegram(message.Chat.Id, TBotStrings.TBotNewUserParameterMising); return; } listUsers = db.GetUserList(); } else if ((eval = Regex.Match(message.Text, "!" + TBotCommand.SQLREMOVEUSER.ToString().ToLower() + "\\s+(.*)", RegexOptions.IgnoreCase)) != null && eval.Success && listUsers.Exists(x => x.Username == message.From.Username && x.IsAdmin)) { if (!string.IsNullOrEmpty(eval.Groups[1].ToString())) { int id = 0; if (int.TryParse(eval.Groups[1].ToString(), out id)) { await SendMsgToTelegram(message.Chat.Id, string.Format(TBotStrings.TBotUserIDRemoved, id, db.RemoveUser(id).ToString())); } else { string user = eval.Groups[1].ToString(); await SendMsgToTelegram(message.Chat.Id, string.Format(TBotStrings.TBotUserNameRemoved, user, db.RemoveUser(user).ToString())); } } else { await SendMsgToTelegram(message.Chat.Id, TBotStrings.TBotCMDArgumentMissing); return; } listUsers = db.GetUserList(); } else if ((eval = Regex.Match(message.Text, "!" + TBotCommand.SQLUPDATEUSER.ToString().ToLower() + "\\s+(.*)\\s+(.*)", RegexOptions.IgnoreCase)) != null && eval.Success && listUsers.Exists(x => x.Username == message.From.Username && x.IsAdmin)) { if (!string.IsNullOrEmpty(eval.Groups[1].ToString()) && !string.IsNullOrEmpty(eval.Groups[2].ToString())) { int id = 0; if (int.TryParse(eval.Groups[1].ToString(), out id)) { bool isAdmin = false; if (bool.TryParse(eval.Groups[2].ToString(), out isAdmin)) { await SendMsgToTelegram(message.Chat.Id, string.Format(TBotStrings.TBotUserUpdated, db.UpdateUser(id, isAdmin).Result)); } else { await SendMsgToTelegram(message.Chat.Id, string.Format(TBotStrings.TBotUserUpdated, false)); } } } else { await SendMsgToTelegram(message.Chat.Id, TBotStrings.TBotCMDWrongArg); return; } listUsers = db.GetUserList(); } } catch (ExceptionGoogleResultItemsNULL ex) { Console.WriteLine(ex.Message); await SendMsgToTelegram(message.Chat.Id, ex.Message); } catch (Exception ex) { Console.WriteLine(ex.Message); await SendMsgToTelegram(message.Chat.Id, ex.Message); } }