public async Task RunAsync() { _logger.LogTrace("RunAsync()"); // open profile await _seleniumWrapper.Click(_instagramOptions.CssHeaderMyself); await _seleniumWrapper.Click(_instagramOptions.CssHeaderMyselfProfile); // must be here, else the auth have failed // open followers popup await _seleniumWrapper.Click(_instagramOptions.CssContactsFollowers); // find int followDone = 0; int followTodo = PseudoRandom.Next(_followBackOptions.FollowMin, _followBackOptions.FollowMax); IWebElement element = _seleniumWrapper.GetElement(_instagramOptions.CssFollowerFollowable, canBeMissing: true); while (element != null && followDone < followTodo) { // like _logger.LogDebug("Following"); await _seleniumWrapper.ScrollIntoView(element, thenWait : false); // bigger waiter altready present after await _waitAction.PreFollowWait(); await _seleniumWrapper.Click(element); _seleniumWrapper.CrashIfPresent(_instagramOptions.CssActionWarning, InstagramOptions.CssActionWarningErrorMessage); followDone++; // prepare next element = _seleniumWrapper.GetElement(_instagramOptions.CssFollowerFollowable, canBeMissing: true); } if (followDone == followTodo) { _logger.LogDebug("Follow back actions : {0} follow", followDone); } else { _logger.LogInformation("Follow back actions : {0}/{1} follow (not all done, seem not any more user to follow back)", followDone, followTodo); } // close the popup await _seleniumWrapper.Click(_instagramOptions.CssContactsClose); throw new NotImplementedException(); }
/// <summary> /// Load selenium action /// </summary> internal async Task LoadSelenium() { _logger.LogTrace("LoadSelenium()"); // Set Options ChromeOptions options = new ChromeOptions { PageLoadStrategy = PageLoadStrategy.Normal }; string w = PseudoRandom.Next(_seleniumOptions.WindowMinW, _seleniumOptions.WindowMaxW) .ToString(CultureInfo.InvariantCulture); string h = PseudoRandom.Next(_seleniumOptions.WindowMinH, _seleniumOptions.WindowMaxH) .ToString(CultureInfo.InvariantCulture); options.AddArgument("--window-size=" + w + "," + h); // try to randomize the setup in order to reduce detection foreach (string a in _seleniumOptions.BrowserArguments .Split('|', StringSplitOptions.RemoveEmptyEntries)) { options.AddArgument(a); } // Init Local or remote SeleniumDrivers if (string.IsNullOrWhiteSpace(_seleniumOptions.RemoteServer)) { _logger.LogDebug("NewChromeSeleniumWrapper({0}, {1}, {2})", Program.ExecutablePath, w, h); WebDriver = new ChromeDriver(Program.ExecutablePath, options); } else { await Task.Delay(_seleniumOptions.RemoteServerWarmUpWaitMs); if (!Uri.TryCreate(_seleniumOptions.RemoteServer, UriKind.Absolute, out Uri uri)) // may be a hostname ? { uri = new Uri("http://" + _seleniumOptions.RemoteServer + ":4444/wd/hub"); } WebDriver = new RemoteWebDriver(uri, options); } // last setup NormalWaiter = TimeSpan.FromSeconds(_seleniumOptions.TimeoutSec); WebDriver.Manage().Timeouts().PageLoad = NormalWaiter; WebDriver.Manage().Timeouts().ImplicitWait = NormalWaiter; WebDriver.Manage().Timeouts().AsynchronousJavaScript = NormalWaiter; // init usefull drivers JsDriver = (IJavaScriptExecutor)WebDriver; }
internal async Task PostScroolWait() { _logger.LogTrace("PostScroolWait()"); await Task.Delay(PseudoRandom.Next(_waitOptions.PostScroolStepMinWaitMs, _waitOptions.PostScroolStepMaxWaitMs)); }
/// <summary> /// WAIT task /// </summary> public async Task RunAsync() { _logger.LogTrace("RunAsync()"); await Task.Delay(PseudoRandom.Next(_waitOptions.WaitTaskMinWaitMs, _waitOptions.WaitTaskMaxWaitMs)); }