[英]C# selenium instagram login issue
大家好,我媽媽最近為他的工作創建了 instagram 帳戶,我想讓他在 selenium 中自動跟隨機器人,但是每當我嘗試測試這幾次時,instagram 都會說請在幾分鍾后重試,但它只是在之后一直說5-10-20 分鍾甚至幾小時有什么建議嗎? 我該如何測試? 使用此代碼只需登錄並在主頁中向下滾動,您可以在其中隨機關注人們,但我無法關注所有人,我如何每次都找到關注按鈕?
using System;
using System.Collections.Generic;
using System.Threading;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Support.UI;
namespace InstagramFollower
{
class Program
{
private static readonly string Pusername = "sorrycantshare";
private static readonly string Ppassword = "sorrycantshare";
private static int sayac = 1;
public static IWebDriver driver = new ChromeDriver();
static void Main()
{
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(100));
driver.Navigate().GoToUrl("https://www.instagram.com/");
//driver.Manage().Window.Maximize();
Console.WriteLine("Siteye açıldı");
wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible(By.Name("username")));
IWebElement username = driver.FindElement(By.Name("username"));
IWebElement password = driver.FindElement(By.Name("password"));
IWebElement loginbtn = driver.FindElement(By.CssSelector(".Igw0E.IwRSH.eGOV_._4EzTm"));
username.SendKeys(Pusername);
password.SendKeys(Ppassword);
loginbtn.Click();
Console.WriteLine("Hesaba giriş yapıldı");
ElementToClickableCssSelector(".sqdOP.L3NKy.y3zKF");
driver.Navigate().GoToUrl($"https://www.instagram.com");
Console.WriteLine("Anasayfaya yönlendirildi");
ElementToClickableCssSelector(".aOOlW.HoLwm");
IWebElement notNow = driver.FindElement(By.CssSelector(".aOOlW.HoLwm"));
notNow.Click();
IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
js.ExecuteScript("window.scrollTo(0, document.body.scrollHeight);");
Thread.Sleep(1500);
js.ExecuteScript("window.scrollTo(0, document.body.scrollHeight);");
Thread.Sleep(2500);
ElementToClickableCssSelector(".Szr5J._6CZji");
Listpeople();
Thread.Sleep(3500);
/*
IWebElement followbtn = driver.FindElement(By.CssSelector(".sqdOP.L3NKy._4pI4F.y3zKF"));
followbtn.Click(); // It follows first person on line but It gives error for others.
*/
}
public static void Listpeople()
{
IReadOnlyCollection<IWebElement> followersname = driver.FindElements(By.CssSelector(".FPmhX.notranslate.Qj3-a"));
IWebElement nextbtn = driver.FindElement(By.CssSelector(".Szr5J._6CZji"));
foreach (IWebElement follower in followersname)
{
Console.WriteLine(sayac.ToString() + " ==> " + follower.Text);
sayac++;
if (sayac == 8)
{
nextbtn.Click();
}
}
}
public static void ElementToClickableCssSelector(string target)
{
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(100));
wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementToBeClickable(By.CssSelector(target)));
}
}
}
好吧,我不得不閱讀一些關於它的主題,結果 instagram 檢測到 selenium webdriver 但我相信我的情況是不同的。我收到錯誤的原因請稍后再試是因為我的帳戶沒有注銷,每次我登錄和測試時在我停止構建並關閉 cmd 和瀏覽器后,它不會注銷。我現在正在寫一個空以在我測試后注銷
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.