Y
Y
yraiv2022-04-12 15:40:57
Google Chrome
yraiv, 2022-04-12 15:40:57

How to launch multiple browsers at the same time?

Hello. There is a list of proxies (ip, port, login password, etc.). I need the program to automatically go through the list and select data from it, with the help of which it enters the site and does its business. How to do it? I can implement a loop that will use data of the type Password[i] login[i], i++ and so on in a circle, but it will go one after another, therefore it will take a very long time and this option is not suitable. I want to make sure that as many browsers as possible are opened, as many as there are passwords. How to do it?

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Interactions;
using System.Threading;
using OpenQA.Selenium.Chrome.ChromeDriverExtensions;
using System.IO;
 
namespace ILoveCyberFourm
{
    public partial class Form1 : Form
    {
 
        IWebDriver Browser;
        public string fileProxyName = @"";
        public int MaxViews;
        public string razdelitel;
        public List<string> ProxyIp = new List<string>();
        public List<int> ProxyPort = new List<int>();
        public List<string> ProxyLogin = new List<string>();
        public List<string> ProxyPassword  =new List<string>();
 
 
        public Form1()
        {
            InitializeComponent();
            LabelMaxViewText();
            openFileDialog1.Filter = "Текстовый документ | *.txt";
            
 
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
 
            ChromeOptions options = new ChromeOptions();      
            options.AddArgument("--user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Firefox/78.0");
     //       options.AddArgument("ignore-certificate-errors");
            options.AddArguments("--disable-blink-features");
            options.AddArgument("--disable-blink-features=AutomationControlled");
            options.AddExcludedArgument("enable-automation");
            options.AddArguments("--disable-infobars");       
            options.AddHttpProxy(ProxyIp[0],ProxyPort[0],ProxyPassword[0],ProxyLogin[0]); // в качестве примера просто
            //  options.AddArguments("headless"); // Скрытие браузера
    
                Browser = new OpenQA.Selenium.Chrome.ChromeDriver(options);
                Browser.Manage().Window.Maximize();
                Browser.Navigate().GoToUrl("https://тут сайт мой нужный");
                Browser.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5);
                CheckAcceptOption();
                IWebElement FindTextBoxSearch = Browser.FindElement(By.ClassName("char-header-search-module__input"));
                FindTextBoxSearch.SendKeys(textBoxFindVideo.Text + OpenQA.Selenium.Keys.Enter);
                OD();
 
            
 
        }
 
 
        private void CheckAcceptOption()
        {
            Actions actionProvider = new Actions(Browser);
            IWebElement FindOption = Browser.FindElement(By.CssSelector(".char-base-button-module__button.char-base-button-module__contained-accent.char-base-button-module__pointerCursor.char-base-button-module__regular"));
            if (FindOption != null)
            {
                actionProvider.Click(FindOption).Perform();
            }
            else return;
        }
 
 
        private void OD()
        {
            Actions actionProvider = new Actions(Browser);
            IWebElement FindVideo = Browser.FindElement(By.ClassName("pen-h-card-inline__image-wrapper"));
            actionProvider.Click(FindVideo).Perform();
 
        }
 
      
 
        private void LabelMaxViewText()
        {
            LabelMax.Text = "максимально возможное количество = " + MaxViews.ToString();
        }
 
        private void button2_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                fileProxyName = openFileDialog1.FileName;
            }
        }
 
        private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
        {
 
        }
 
        private void button3_Click(object sender, EventArgs e)
        {
            string[] split;
            StreamReader Filen = new StreamReader(fileProxyName);
            while ((razdelitel = Filen.ReadLine()) != null)
            {
               
                split = razdelitel.Split(':');
                var timeIpProxy = split[0];
                var timePortProxy = split[1];
                var timeProxyLogin = split[2];
                var timeProxyPassword = split[3];
                ProxyIp.Add(timeIpProxy);
                int x = Int32.Parse(timePortProxy);
                ProxyPort.Add(x);
                ProxyLogin.Add(timeProxyLogin);
                ProxyPassword.Add(timeProxyPassword);
                MaxViews++;
            }
            LabelMaxViewText();
            Filen.Close();
        }
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
rPman, 2022-04-12
@rPman

try adding --profile-directory="Profile 1" to the browser command line, where "profile 1" is the name of the profile, or rather the subdirectory where it will be saved
for each browser create your own IWebDriver

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question