Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Data.SqlClient;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using OpenQA.Selenium;
- using OpenQA.Selenium.Support.UI;
- namespace WindowsFormsApplication1
- {
- public partial class Form1 : Form
- {
- IWebDriver Browser;
- public Form1()
- {
- InitializeComponent();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- Browser.Navigate().GoToUrl("https://www.instagram.com/explore/");
- IWebElement SearchInput = Browser.FindElement(By.TagName("input"),10);
- string Tag = HashTagText.Text;
- SearchInput.SendKeys(Tag);
- System.Threading.Thread.Sleep(3000);
- SearchInput.SendKeys(OpenQA.Selenium.Keys.Enter);
- }
- private void button2_Click(object sender, EventArgs e)
- {
- Browser.Quit();
- }
- private void button4_Click(object sender, EventArgs e)
- {
- Browser = new OpenQA.Selenium.Chrome.ChromeDriver();
- Browser.Manage().Window.Maximize();
- Browser.Navigate().GoToUrl("https://www.instagram.com");
- IWebElement Login = Browser.FindElement(By.XPath(@"//*[@id="+"\""+@"react-root" + "\""+@"]/section/main/article/div[2]/div[2]/p/a"),10);
- Login.Click();
- IWebElement UserName = Browser.FindElement(By.Name("username"),10);
- // UserName.SendKeys("Instagram20_17@mail.ru");
- SqlConnection con = new SqlConnection(@"Data Source=DESKTOP-I33KJCN\SQLEXPRESS;Initial Catalog=insta_bot;Integrated Security=True");
- con.Open();
- string query = "SELECT login,password FROM USERS where id = 2";
- SqlCommand command = new SqlCommand(query,con);
- SqlDataReader reader = command.ExecuteReader();
- string pc = null;
- string pc1 = null;
- while (reader.Read())
- {
- pc = reader[0].ToString();
- pc1 = reader[1].ToString();
- }
- UserName.SendKeys(pc);
- IWebElement Password = Browser.FindElement(By.Name("password"),10);
- //Password.SendKeys("6qPdsfDcGy4fm3WVEKaV" + OpenQA.Selenium.Keys.Enter);
- Password.SendKeys(pc1 + OpenQA.Selenium.Keys.Enter);
- con.Close();
- }
- private void button3_Click(object sender, EventArgs e)
- {
- backgroundWorker1.CancelAsync();
- }
- private void button5_Click(object sender, EventArgs e)
- {
- backgroundWorker1.RunWorkerAsync();
- }
- public void Subcribe (object sender, DoWorkEventArgs e)
- {
- // IWebElement FirstElement = Browser.FindElement(By.CssSelector("._nljxa ._ovg3g"),10);
- IWebElement FirstElement = Browser.FindElement(By.XPath (@"//*[@id="+"\""+@"react-root"+"\""+@"]/section/main/article/div[2]/div[1]/div[1]/a[1]/div/div[2]"), 10);
- //*[@id="react-root"]/section/main/article/div[2]/div[1]/div[1]/a[1]/div/div[2]
- FirstElement.Click();
- Wait(500);
- //int Count = Decimal.
- for (int i = 0; i < Decimal.ToInt32(SubscribeCountEnter.Value); i++)
- {
- if (backgroundWorker1.CancellationPending) return;
- if(!SubscribeAction())i--;
- LikeAction();
- NextAction();
- }
- IWebElement Close = Browser.FindElement(By.CssSelector("button._3eajp"),10);
- Close.Click();
- Wait(500);
- MessageBox.Show("Мы подписались на " + SubscribeCountEnter.Value + " аккаунтов");
- }
- public Boolean SubscribeAction()
- {
- IWebElement g = Browser.FindElement(By.CssSelector("._fbms8 ._ah57t"),10);
- Wait(500);
- if (g.Text == "Подписаться")
- {
- g.Click();
- Wait(1000);
- return true;
- }
- else
- {
- Wait(1000);
- return false;
- }
- }
- public void LikeAction()
- {
- IWebElement LikeBtn = Browser.FindElement(By.CssSelector("section._jveic a ._soakw"), 10);
- if (LikeBtn.Text == "Нравится")
- {
- LikeBtn.Click();
- }
- Wait(700);
- }
- public void NextAction()
- {
- IWebElement NextBtn = Browser.FindElement(By.LinkText("Далее"), 10);
- NextBtn.Click();
- }
- public void Wait(int f)
- {
- System.Threading.Thread.Sleep(f);
- }
- private void button6_Click(object sender, EventArgs e)
- {
- // Cookie cookie = new Cookie("key", "value");
- //Browser.Manage().Cookies.AddCookie(cookie);
- SqlConnection con = new SqlConnection(@"Data Source=DESKTOP-I33KJCN\SQLEXPRESS;Initial Catalog=insta_bot;Integrated Security=True");
- con.Open();
- var allCookies = Browser.Manage().Cookies.AllCookies;
- foreach (Cookie cookie in allCookies)
- {
- string str = cookie.ToString();
- //MessageBox.Show(str, "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
- string query = "INSERT INTO [User_Cookie] (user_id, cookie) VALUES(2, @cookie)";
- SqlCommand command = new SqlCommand(query, con);
- command.Parameters.AddWithValue("cookie", str);
- command.ExecuteNonQuery();
- }
- con.Close();
- }
- /* private void Sell(object sender, DoWorkEventArgs e)
- {
- IWebElement SteamContainer = Browser.FindElement(By.ClassName("inventory_ctn"));
- int CardsProcessed = 0;
- bool FirstSell = true;
- List<IWebElement> Items = SteamContainer.FindElements(By.ClassName("itemHolder")).ToList();
- for (int i = 0; i < Items.Count; i++)
- {
- if (backgroundWorker1.CancellationPending) return;
- if (Items[i].GetAttribute("style") == "")
- {
- System.Threading.Thread.Sleep(2000);
- Items[i].Click();
- String DivText = "";
- IWebElement SellBtn = null;
- System.Threading.Thread.Sleep(1000);
- List<IWebElement> SellDivs = Browser.FindElements(By.ClassName("item_market_actions")).ToList();
- for (int j = 0; j < SellDivs.Count; j++)
- {
- if (SellDivs[j].Displayed)
- {
- DivText = SellDivs[j].Text;
- SellBtn = SellDivs[j].FindElement(By.CssSelector(".item_market_action_button.item_market_action_button_green"));
- }
- }
- String priceStr = System.Text.RegularExpressions.Regex.Match(DivText, @"[0-9]+\,?[0-9]*").Value;
- float Price = Single.Parse(priceStr) + (float)nudPriceChange.Value;
- Actions SellClick = new Actions(Browser);
- SellClick.MoveToElement(SellBtn).Click().Perform();
- //SellBtn.Click();
- System.Threading.Thread.Sleep(2000);
- if (FirstSell)
- {
- Browser.FindElement(By.Id("market_sell_dialog_accept_ssa")).Click();
- FirstSell = false;
- }
- Browser.FindElement(By.Id("market_sell_buyercurrency_input")).SendKeys(Price.ToString());
- System.Threading.Thread.Sleep(1000);
- Browser.FindElement(By.Id("market_sell_dialog_accept")).Click();
- System.Threading.Thread.Sleep(1000);
- Browser.FindElement(By.Id("market_sell_dialog_ok")).Click();
- System.Threading.Thread.Sleep(3000);
- Browser.FindElement(By.CssSelector(".newmodal_buttons .btn_grey_white_innerfade.btn_medium")).Click();
- CardsProcessed++;
- if (CardsProcessed == 25)
- {
- CardsProcessed = 0;
- Browser.FindElement(By.Id("pagebtn_next")).Click();
- System.Threading.Thread.Sleep(2000);
- }
- }
- }
- }*/
- }
- public static class WebDriverExtensions
- {
- public static IWebElement FindElement(this IWebDriver Browser, By by, int timeoutInSeconds)
- {
- if (timeoutInSeconds > 0)
- {
- var wait = new WebDriverWait(Browser, TimeSpan.FromSeconds(timeoutInSeconds));
- return wait.Until(Brs => Brs.FindElement(by));
- }
- return Browser.FindElement(by);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement