private RequestResult AddComment(Media media, string commentText) { RequestResult result = null; WebDriver.Navigate().GoToUrl(media.Link); var commentResult = WebDriver.WaitUntil(By.XPath("//a[@title='" + UserName + "' and contains(text(), '" + UserName + "')] "), 5); int counter = 0; do { if (commentResult == null) // if comment not exists { var commentField = WebDriver.WaitUntil(By.ClassName("-cx-PRIVATE-PostInfo__commentCreatorInput"), 10); if (commentField == null) { if (counter != 2) { counter++; continue; } break; } commentField.SendKeys(commentText.Trim()); commentField.SendKeys(Keys.Return); commentResult = WebDriver.WaitUntil(By.XPath("//a[@title='" + UserName.ToLower() + "' and contains(text(), '" + UserName.ToLower() + "')] "), 5); if (commentResult != null) { result = new RequestResult(commentText, media.User.Id, UserId, media.Link, RequestType.Comment, media.Id); break; } } } while (counter != 2); //todo: сделать колличество попыток настраиваемым для юзера return result; }
private RequestResult AddLike(Media media) { RequestResult result = null; WebDriver.Navigate().GoToUrl(media.Link); var likeButton = WebDriver.WaitUntil(By.ClassName("coreSpriteHeartOpen"), 5); if (likeButton != null) { string id = media.Id.Substring(0, media.Id.IndexOf("_")); string script = "window.vazr = ''; $.ajax({ url: 'https://instagram.com/web/likes/" + id + "/like/', type: 'POST'}).done(function( msg ) { window.vazr = msg.status == 'ok'? '1' : '0'; }).fail(function( jqXHR, textStatus ) {window.vazr = '0';});"; ExecuteJavaScript(script); //1047724894729627550 WaitAjax(); string vazr = (string)ExecuteJavaScript("return window.vazr;"); if (vazr == "1") result = new RequestResult("", media.User.Id, UserId, media.Link, RequestType.Like, media.Id); } else { return new RequestResult("", 0, 0, "", RequestType.Like, media.Id); } return result; }