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; }
public async Task RunAsync() { _logger.LogTrace("RunAsync()"); await _seleniumWrapper.ScrollToTopAsync(); // open await _seleniumWrapper.Click(_instagramOptions.CssHeaderButtonHome); // scrools await _seleniumWrapper.ScrollToBottomAsync(_homePageActionsOptions.InitScrools); // find int likeDone = 0; int likeTodo = DoLike ? PseudoRandom.Next(_homePageActionsOptions.LikeMin, _homePageActionsOptions.LikeMax) : 0; IWebElement element = _seleniumWrapper.GetElement(_instagramOptions.CssPhotoLike, canBeMissing: true); while (element != null && likeDone < likeTodo) { // like _logger.LogDebug("Liking"); await _seleniumWrapper.ScrollIntoView(element, thenWait : false); // bigger waiter alredy present after await _waitAction.PreLikeWait(); await _seleniumWrapper.Click(element); _seleniumWrapper.CrashIfPresent(_instagramOptions.CssActionWarning, InstagramOptions.CssActionWarningErrorMessage); likeDone++; // prepare next await _seleniumWrapper.ScrollToBottomAsync(); element = _seleniumWrapper.GetElement(_instagramOptions.CssPhotoLike, canBeMissing: true); } if (likeDone == likeTodo) { _logger.LogDebug("Home page actions : {0} like", likeDone); } else { _logger.LogWarning("Home page actions : {0}/{1} liked (not all done, you may increase scrool or reduce frequency)", likeDone, likeTodo); } }
public async Task RunAsync() { _logger.LogTrace("RunAsync()"); await _seleniumWrapper.ScrollToTopAsync(); // open if require if (_seleniumWrapper.CurrentUrl != _persistenceManager.Session.UserContactUrl) { await _seleniumWrapper.Click(_instagramOptions.CssHeaderMyself); await _seleniumWrapper.Click(_instagramOptions.CssHeaderMyselfProfile); // must be here, else the auth have failed } // need to get a new list HashSet<string> myFollowers = await GetMyFollowers(); // open Following popup await _seleniumWrapper.Click(_instagramOptions.CssContactsFollowing); // loop until no more element await _seleniumWrapper.ScrollToBottomAsync(_instagramOptions.CssContactsListScrollable); // Get the list HashSet<string> myFollowing = new HashSet<string>(_seleniumWrapper.GetAttributes(_instagramOptions.CssContactUrl)); myFollowing.ExceptWith(myFollowers); _logger.LogDebug("Found {0} currently followed but not follower", myFollowing.Count); // find int unfollowDone = 0; int unfollowTodo = PseudoRandom.Next(_unfollowUnfollowersOptions.UnfollowMin, _unfollowUnfollowersOptions.UnfollowMax); IWebElement element = GetNextElement(myFollowing); while (element != null && unfollowDone < unfollowTodo) { _logger.LogDebug("Unfollowing"); // Unfollowing popup await _seleniumWrapper.ScrollIntoView(element, thenWait: false); // bigger waiter altready present after await _waitAction.PreFollowWait(); await _seleniumWrapper.Click(element); // Unfollowing action await _seleniumWrapper.Click(_instagramOptions.CssContactUnfollowConfirm); _seleniumWrapper.CrashIfPresent(_instagramOptions.CssActionWarning, InstagramOptions.CssActionWarningErrorMessage); unfollowDone++; // prepare next element = GetNextElement(myFollowing); } if (unfollowDone == unfollowTodo) { _logger.LogDebug("Unfollow actions : {0} unfollowed", unfollowDone); } else { _logger.LogDebug("Unfollow actions : {0}/{1} unfollowed (not all done, seem not any more user to unfollow)", unfollowDone, unfollowTodo); } // close the popup await _seleniumWrapper.Click(_instagramOptions.CssContactsClose); }
public async Task RunAsync() { _logger.LogTrace("RunAsync()"); await _seleniumWrapper.ScrollToTopAsync(); // open await _seleniumWrapper.Click(_instagramOptions.CssHeaderButtonExplore); // Wait loading if required await _seleniumWrapper.WaitLoader(_instagramOptions.CssExploreLoading); // scrools await _seleniumWrapper.ScrollToBottomAsync(_explorePhotosPageActionsOptions.InitScrools); // find int followDone = 0; int likeDone = 0; int followTodo = DoFollow ? PseudoRandom.Next(_explorePhotosPageActionsOptions.FollowMin, _explorePhotosPageActionsOptions.FollowMax) : 0; int likeTodo = DoLike ? PseudoRandom.Next(_explorePhotosPageActionsOptions.LikeMin, _explorePhotosPageActionsOptions.LikeMax) : 0; IWebElement element = _seleniumWrapper.GetElement(_instagramOptions.CssExplorePhotos); while (element != null && (likeDone < likeTodo || followDone < followTodo)) { _logger.LogDebug("Opening a post"); await _seleniumWrapper.ScrollIntoView(element); await _seleniumWrapper.Click(element); // TOFIX : In some case, the popup seem to fail to open and then _seleniumWrapper.Click(_instagramOptions.CssPhotoClose); will fail or click on the current customer icon and open user profil, next actions will faild then // Follow if (followDone < followTodo && _seleniumWrapper.GetElementIfPresent(_instagramOptions.CssPhotoFollow, out IWebElement btnFollow)) { _logger.LogDebug("Following"); await _waitAction.PreFollowWait(); await _seleniumWrapper.Click(btnFollow); _seleniumWrapper.CrashIfPresent(_instagramOptions.CssActionWarning, InstagramOptions.CssActionWarningErrorMessage); followDone++; } // like if (likeDone < likeTodo && _seleniumWrapper.GetElementIfPresent(_instagramOptions.CssPhotoLike, out IWebElement btnLike)) { _logger.LogDebug("Liking"); await _waitAction.PreLikeWait(); await _seleniumWrapper.Click(btnLike); _seleniumWrapper.CrashIfPresent(_instagramOptions.CssActionWarning, InstagramOptions.CssActionWarningErrorMessage); likeDone++; } // close modal page without waiter await _seleniumWrapper.Click(_instagramOptions.CssPhotoClose); // prepare next await _seleniumWrapper.ScrollToBottomAsync(); element = _seleniumWrapper.GetElement(_instagramOptions.CssExplorePhotos); } if (likeDone == likeTodo) { _logger.LogDebug("Explore Photos page actions : {0} like, {1} follow", likeDone, followDone); } else { _logger.LogWarning("Explore Photos page actions : {0}/{1} like, {2}/{3} follow (not all done, you may increase scrool or reduce frequency)", likeDone, likeTodo, followDone, followTodo); } }
internal async Task PreLikeWait() { _logger.LogTrace("PreLikeWait()"); await Task.Delay(PseudoRandom.Next(_waitOptions.PreLikeMinWaitMs, _waitOptions.PreLikeMaxWaitMs)); }
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)); }