C#selenium instagram登录问题



大家好,最近我妈妈为他的工作创建了instagram帐户,我想让他成为硒元素的自动追随者机器人,但每当我尝试测试这几次时,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检测到硒网络驱动程序,但我相信我的情况不同。我收到错误的原因是,请稍后再试,因为我的帐户没有注销,每次我登录并测试后,我都会停止构建并关闭cmd和浏览器,这样它就不会注销。我现在正在写一个空白,在我测试后注销

最新更新