//MAIN CODE TO LOAD HANDBAGS
        private void WorkerMine_DoWork()
        {
            //Set Progress Text to "0/0"
            SetLabelTextDelegate setLabelTextDelegate = new SetLabelTextDelegate(SetLabelText);
            String progressTextString = "0/0";

            this.Invoke(setLabelTextDelegate, new object[] { "progressText", progressTextString });
            productsLoaded = false;

            //Create a box with 4 default spots + more depending on how many bags are present
            WebBrowser webBrowser    = new WebBrowser();
            int        defaultWidth  = 550;
            int        defaultHeight = 550;
            Panel      leftPanel     = new Panel
            {
                Name       = "leftPanel",
                Location   = new Point(30, 30),
                Size       = new Size(defaultWidth, defaultHeight),
                AutoScroll = false,
                BackColor  = Color.Gray,
            };

            leftPanel.VerticalScroll.Visible = false;

            //Click Event
            this.Click      += clickEvent;
            leftPanel.Click += clickEvent;
            AddPanelDelegate addPanel = new AddPanelDelegate(AddPanel);

            this.Invoke(addPanel, new object[] { leftPanel });

            //Variables for item boxes
            int xCoord = 0;
            int yCoord = 0;

            //Check if the user wants to get stock data (slow as it uses a web browser)
            bool getStock = false;

            if (stockCheckBox.Checked)
            {
                getStock = true;
            }

            //Load an instance of Internet Explorer 11 for Web Browsing
            if (getStock)
            {
                webBrowser.ScriptErrorsSuppressed = true;
                if (!WBEmulator.IsBrowserEmulationSet())
                {
                    WBEmulator.SetBrowserEmulationVersion();
                }
                //Web Browser Event
                webBrowser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(JavaScriptLoaded);
            }

            //Using the HTML Agility NuGet
            HtmlAgilityPack.HtmlWeb      htmlWeb     = new HtmlWeb();
            HtmlAgilityPack.HtmlDocument webPage     = new HtmlAgilityPack.HtmlDocument();
            HtmlAgilityPack.HtmlDocument webPageDesc = new HtmlAgilityPack.HtmlDocument();
            webPage = htmlWeb.Load("https://uk.louisvuitton.com/eng-gb/women/handbags/_/N-2keomb.html");

            //Collect HTML Data
            HtmlAgilityPack.HtmlNodeCollection productNames     = webPage.DocumentNode.SelectNodes("//div[@class='productName toMinimize']");
            HtmlAgilityPack.HtmlNodeCollection productPrices    = webPage.DocumentNode.SelectNodes("//div[@class='from-price']//span");
            HtmlAgilityPack.HtmlNodeCollection productPageLinks = webPage.DocumentNode.SelectNodes("//a[@class='product-item productItem tagClick tagClick']");
            //HtmlAgilityPack.HtmlNodeCollection productPageLinks = webPage.DocumentNode.SelectNodes("//a[@class='product-item tagClick tagClick']");
            HtmlAgilityPack.HtmlNodeCollection productImageLinks = webPage.DocumentNode.SelectNodes("//a[@class='product-item productItem tagClick tagClick']//div[@class='imageWrapper']//img");

            //Progress Bar
            InitialseProgressBar(productNames.Count);

            //Collect JavaScript Data + Add Item to Form
            handbags.Clear();
            for (int i = 0; i < productNames.Count; i++)
            {
                //Create Handbag Object
                handbags.Add(new Handbag());

                //Product Name
                handbags.ElementAt(i).ProductName = productNames.ElementAt(i).InnerText;

                //Product Price
                handbags.ElementAt(i).ProductPrice = productPrices.ElementAt(i).Attributes["data-htmlContent"].Value;

                //Product Code
                handbags.ElementAt(i).ProductCode = productPageLinks.ElementAt(i).Attributes["data-sku"].Value;

                //Image Link
                handbags.ElementAt(i).ProductImage = productImageLinks.ElementAt(i).Attributes["data-src"].Value;
                handbags.ElementAt(i).ProductImage = handbags.ElementAt(i).ProductImage.Replace("{IMG_WIDTH}", "360");
                handbags.ElementAt(i).ProductImage = handbags.ElementAt(i).ProductImage.Replace("{IMG_HEIGHT}", "360");
                handbags.ElementAt(i).ProductImage = handbags.ElementAt(i).ProductImage.Replace(" ", "%20");

                //Page Link
                handbags.ElementAt(i).PageLink = "https://uk.louisvuitton.com/" + productPageLinks.ElementAt(i).Attributes["href"].Value;

                //Navigate Browser for JavaScript (The only way to get stock messages is using JavaScript, so the program opens an internet browser)
                if (getStock)
                {
                    LoadWebPageWithBrowser(webPageDesc, handbags.ElementAt(i).PageLink, webBrowser);
                }
                else
                {
                    webPageDesc = htmlWeb.Load(handbags.ElementAt(i).PageLink);
                }

                HtmlAgilityPack.HtmlNode description = webPageDesc.DocumentNode.SelectSingleNode("//div[@class='productDescription description-push-text onlyML ppTextDescription ']");
                if (description != null)
                {
                    handbags.ElementAt(i).ProductDescription = description.InnerText;
                    handbags.ElementAt(i).ProductDescription = handbags.ElementAt(i).ProductDescription.Remove(0, 15);
                }

                //Handbag Availability
                if (getStock)
                {
                    HtmlAgilityPack.HtmlNode availability = webPageDesc.DocumentNode.SelectSingleNode("//div[@id='notInStock']");
                    if (availability != null)
                    {
                        if (availability.Attributes["class"].Value == "getIndexClass")
                        {
                            handbags.ElementAt(i).Availability = "Currently out of stock online";
                        }
                        else
                        {
                            handbags.ElementAt(i).Availability = "In Stock";
                        }
                    }
                }

                //Add Item to Form
                int rowNumber = Convert.ToInt32(Math.Floor(Convert.ToDouble(i) / 2));

                //Get X & Y Coordinates
                yCoord = yMargin + rowNumber * boxSize + yMargin * rowNumber;
                if (i % 2 == 0)
                {
                    xCoord = xMargin;
                }
                else
                {
                    xCoord = columnDistance;
                }

                //Add Box To Panel
                UpdatePanelDelegate updatePanelDelegate = new UpdatePanelDelegate(UpdatePanel);
                this.Invoke(updatePanelDelegate, new object[] { "leftPanel", handbags.ElementAt(i), xCoord, yCoord, boxSize, i });

                //Progress Text
                progressTextString = (i + 1) + "/" + productNames.Count;
                VoidDelegate progressStep = new VoidDelegate(ProgressStep);
                this.Invoke(setLabelTextDelegate, new object[] { "progressText", progressTextString });
                this.Invoke(progressStep);
            }
            //DATA COLLECTED!
            VoidDelegate endProgressBar = new VoidDelegate(EndProgressBar);

            this.Invoke(endProgressBar);
            webBrowser.Dispose();
            webSiteLoaded  = false;
            midwork        = false;
            productsLoaded = true;
        }
Esempio n. 2
0
        public void createAccount(object o)
        {
            int index = (int)o; //the current thread's index

            threadsRunning++;
            creatorThreadsRunning++;
            lblThreadsRunning.SetPropertyThreadSafe(() => lblThreadsRunning.Text, Convert.ToString(threadsRunning));
            lblCreatorThreadsRunning.SetPropertyThreadSafe(() => lblCreatorThreadsRunning.Text, Convert.ToString(creatorThreadsRunning));

            foreach (Hashtable account in inputArray[index])
            {
                string username      = Convert.ToString(account["username"]);
                string password      = Convert.ToString(account["password"]);
                string email         = "";
                string emailPassword = "";
                string proxy         = Convert.ToString(account["proxy"]);

                //lock email list and take the first one and remove it
                lock (emails)
                {
                    if (emails.Count > 0)
                    {
                        //split email and password
                        string   emailpass    = emails.First();
                        string[] emailandpass = emailpass.Split(':');
                        email         = emailandpass[0];
                        emailPassword = emailandpass[1];
                        emails.Remove(email);
                    }
                    else
                    {
                        threadsRunning--;
                        creatorThreadsRunning--;
                        lblThreadsRunning.SetPropertyThreadSafe(() => lblThreadsRunning.Text, Convert.ToString(threadsRunning));
                        lblCreatorThreadsRunning.SetPropertyThreadSafe(() => lblCreatorThreadsRunning.Text, Convert.ToString(creatorThreadsRunning));
                        resetEvents[index].Set(); //signal the thread is done working
                    }
                }

                if (resetEvents[index].WaitOne(0))
                {
                    return;
                }

                //Convert proxy to a WebProxy
                WebProxy proxyObject = new WebProxy(proxy);

                //We're going to store our cookies here for now.
                //Upon successful creation, we will store them in
                //a file to prevent relogging, unnatural looking useage.
                CookieContainer tempCookies = new CookieContainer();

                //This will store the webserver's response to our request
                HttpWebResponse response;

                //This will store our post request data
                HttpWebRequest request;

                //This will be used to read the response
                StreamReader responseReader;

                //This will store the page in plain text
                //string thePage;

                //This will store the page for HTMLAgilityPack
                HtmlAgilityPack.HtmlDocument agilityPage;

                //These are used to properly encode our post data for the server
                UTF8Encoding encoding;
                Byte[]       byteData;

                //This variable will store our unencoded post data
                string postData;

                //This is used to create our POST body
                Stream postRequestStream;

                try
                {
                    //This will help us avoid some 417 errors
                    System.Net.ServicePointManager.Expect100Continue = false;

                    /* STEP 1: Go to to join page */
                    request = (HttpWebRequest)HttpWebRequest.Create("http://fiverr.com/join");

                    request.Method    = "GET";
                    request.Host      = "fiverr.com";
                    request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:19.0) Gecko/20100101 Firefox/19.0";
                    request.Accept    = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
                    request.Headers.Add("Accept-Language: en-US,en;q=0.5");
                    request.Headers.Add("Accept-Encoding: gzip, deflate");
                    request.KeepAlive = true;
                    request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate; //used to view the page in plain text
                    request.Proxy = proxyObject;

                    //Grab the response and store the cookies
                    response = (HttpWebResponse)request.GetResponse();
                    tempCookies.Add(response.Cookies);

                    //Load the page and grab the X-CSRF Token
                    responseReader = new StreamReader(response.GetResponseStream());

                    //Create html doc
                    agilityPage = new HtmlAgilityPack.HtmlDocument();
                    agilityPage.Load(responseReader);

                    //extract token
                    string token = "";
                    string name  = "";
                    foreach (HtmlNode node in agilityPage.DocumentNode.SelectNodes("//meta"))
                    {
                        name = node.GetAttributeValue("name", "");
                        if (name == "csrf-token")
                        {
                            token = node.GetAttributeValue("content", "");
                            break;
                        }
                    }

                    //extract captcha "secret" and break captcha from
                    string captchaSecret = "";
                    foreach (HtmlNode node in agilityPage.DocumentNode.SelectNodes("//input"))
                    {
                        name = node.GetAttributeValue("name", "");
                        if (name == "user[captcha_secret]")
                        {
                            captchaSecret = node.GetAttributeValue("value", "");
                            break;
                        }
                    }

                    //Break dat captcha! Note that this will only solve simple addition captchas and NOT text based ones.
                    HtmlAgilityPack.HtmlNodeCollection captchaQuestion = agilityPage.DocumentNode.SelectNodes("//div[@class='captcha-area']/span");

                    if (captchaQuestion == null)
                    {
                        throw new Exception("Unrecognized captcha type");
                    }

                    string captchaChars = captchaQuestion.ElementAt(0).InnerText;
                    captchaChars.Replace(" ", "");
                    char[] captchaCharArray = captchaChars.ToCharArray();
                    int    numOne           = Convert.ToInt32(captchaCharArray[0].ToString());
                    int    numTwo           = Convert.ToInt32(captchaCharArray[4].ToString());
                    string captchaAnswer    = (numOne + numTwo).ToString();

                    //Now all we need is the "User Spam Answers" data. This is probably an encoded version of the actual answer that Fiverr uses to verify our response.
                    string userSpamAnswers = "";
                    foreach (HtmlNode node in agilityPage.DocumentNode.SelectNodes("//input"))
                    {
                        name = node.GetAttributeValue("name", "");
                        if (name == "user[spam_answers]")
                        {
                            userSpamAnswers = node.GetAttributeValue("value", "");
                            break;
                        }
                    }

                    response.Close();

                    /* STEP 2: Check user */
                    postData = "username="******"http://fiverr.com/checkuser");

                    request.Method    = "POST";
                    request.Host      = "fiverr.com";
                    request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:19.0) Gecko/20100101 Firefox/19.0";
                    request.Accept    = "text/javascript";
                    request.Headers.Add("Accept-Language: en-US,en;q=0.5");
                    request.Headers.Add("Accept-Encoding: gzip, deflate");
                    request.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";
                    request.Headers.Add("X-Requested-With: XMLHttpRequest");
                    request.Headers.Add("X-CSRF-Token: " + token);
                    request.Referer         = "http://fiverr.com/join";
                    request.ContentLength   = byteData.Length;
                    request.CookieContainer = tempCookies;
                    request.KeepAlive       = true;
                    request.Headers.Add("Pragma: no-cache");
                    request.Headers.Add("Cache-Control: no-cache");
                    request.Proxy = proxyObject;

                    postRequestStream = request.GetRequestStream();
                    postRequestStream.Write(byteData, 0, byteData.Length);
                    postRequestStream.Close();

                    //Grab the response
                    response = (HttpWebResponse)request.GetResponse();
                    response.Close();

                    /* STEP 3: Check suspicious email */
                    //Properly encode our data for the server
                    encoding = new UTF8Encoding();
                    byteData = encoding.GetBytes(postData);

                    request = (HttpWebRequest)WebRequest.Create("http://fiverr.com/check_suspicious_email");

                    request.Method    = "POST";
                    request.Host      = "fiverr.com";
                    request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:19.0) Gecko/20100101 Firefox/19.0";
                    request.Accept    = "text/javascript";
                    request.Headers.Add("Accept-Language: en-US,en;q=0.5");
                    request.Headers.Add("Accept-Encoding: gzip, deflate");
                    request.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";
                    request.Headers.Add("X-Requested-With: XMLHttpRequest");
                    request.Headers.Add("X-CSRF-Token: " + token);  //we need to find this token in the previous response
                    request.Referer         = "http://fiverr.com/join";
                    request.ContentLength   = byteData.Length;
                    request.CookieContainer = tempCookies;
                    request.KeepAlive       = true;
                    request.Headers.Add("Pragma: no-cache");
                    request.Headers.Add("Cache-Control: no-cache");
                    request.Proxy = proxyObject;

                    postRequestStream = request.GetRequestStream();
                    postRequestStream.Write(byteData, 0, byteData.Length);
                    postRequestStream.Close();

                    //Grab the response
                    response = (HttpWebResponse)request.GetResponse();
                    response.Close();

                    /* STEP 4: Register the user */
                    //we need to replace values with variables here
                    postData = "utf8=%E2%9C%93" +
                               "&authenticity_token=" + token +
                               "&user%5Binvitation_token%5D=&user%5Bemail%5D=" + email +
                               "&user%5Busername%5D=" + username +
                               "&user%5Bpassword%5D=" + password +
                               "&user%5Bcaptcha_solution%5D=" + captchaAnswer +
                               "&user%5Bcaptcha_secret%5D=" + captchaSecret +
                               "&user%5Bspam_answers%5D=" + userSpamAnswers +
                               "&user%5Bspam_answer%5D=" +
                               "&user%5Bterms_of_use%5D=0" +
                               "&user%5Bterms_of_use%5D=1";

                    //Properly encode our data for the server
                    encoding = new UTF8Encoding();
                    byteData = encoding.GetBytes(postData);

                    request = (HttpWebRequest)WebRequest.Create("http://fiverr.com/users");

                    request.Method    = "POST";
                    request.Host      = "fiverr.com";
                    request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:19.0) Gecko/20100101 Firefox/19.0";
                    request.Accept    = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
                    request.Headers.Add("Accept-Language: en-US,en;q=0.5");
                    request.Headers.Add("Accept-Encoding: gzip, deflate");
                    request.Referer                = "http://fiverr.com/join";
                    request.CookieContainer        = tempCookies;
                    request.KeepAlive              = true;
                    request.ContentType            = "application/x-www-form-urlencoded";
                    request.ContentLength          = byteData.Length;
                    request.Proxy                  = proxyObject;
                    request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate; //used to view the page in plain text

                    postRequestStream = request.GetRequestStream();
                    postRequestStream.Write(byteData, 0, byteData.Length);
                    postRequestStream.Close();

                    //Grab the response and store the cookies
                    response = (HttpWebResponse)request.GetResponse();
                    tempCookies.Add(response.Cookies);

                    //grab the page
                    responseReader = new StreamReader(response.GetResponseStream());
                    //thePage = responseReader.ReadToEnd();

                    //We can use HTMLAgilityPack to scrape the redirect link here
                    //Create html doc
                    agilityPage = new HtmlAgilityPack.HtmlDocument();
                    agilityPage.Load(responseReader);

                    //search html for "please verify your account"
                    if (agilityPage.DocumentNode.InnerHtml.Contains("Please activate your account"))
                    {
                        //SUCCESS!
                        //save the cookies for this username as username.dat in /cookies folder
                        WriteCookiesToDisk(Path.Combine(Environment.CurrentDirectory, "cookies", username + ".dat"), tempCookies);

                        //increase successful counter
                        createdAccounts++;
                        lblAccountsCreated.SetPropertyThreadSafe(() => lblAccountsCreated.Text, Convert.ToString(createdAccounts));
                        txtLog.SetPropertyThreadSafe(() => txtLog.Text, "Successfully created account " + username + System.Environment.NewLine + txtLog.Text);

                        //pause to make sure we get the email
                        Thread.Sleep(2000);

                        //grab verification link
                        string verifyLink = verifyHotmail(email, emailPassword, @"(https?):((//)|(\\\\))+fiverr\.com/+[\w\d:#@%/;$()~_?\+-=\\\.&]*", "Fiverr: Activate");

                        //Verify the account! Complete success if all goes as planned here!
                        request = (HttpWebRequest)HttpWebRequest.Create(verifyLink);

                        request.Method    = "GET";
                        request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:19.0) Gecko/20100101 Firefox/19.0";
                        request.KeepAlive = true;
                        request.Host      = "fiverr.com";
                        request.Headers.Add("Accept-Encoding: gzip, deflate");
                        request.Headers.Add("Accept-Language: en-us");
                        request.CookieContainer        = tempCookies;
                        request.Proxy                  = proxyObject;
                        request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate; //used to view the page in plain text

                        HttpWebResponse postresponse  = (HttpWebResponse)request.GetResponse();
                        StreamReader    postreqreader = new StreamReader(postresponse.GetResponseStream());

                        string thePage = postreqreader.ReadToEnd();
                        if (thePage.Contains("Account successfully activated"))
                        {
                            //Hurray! We rule Fiverr!
                            verifiedAccounts++;
                            lblAccountsVerrified.SetPropertyThreadSafe(() => lblAccountsVerrified.Text, Convert.ToString(verifiedAccounts));
                            txtLog.SetPropertyThreadSafe(() => txtLog.Text, "Successfully verrified account " + username + System.Environment.NewLine + txtLog.Text);
                            verifiedAccountsList.Add(account);
                        }
                    }
                }
                catch (WebException wex)
                {
                    lock (unusedemails)
                        emails.Add(email + ':' + emailPassword); //readd our unused email

                    txtLog.SetPropertyThreadSafe(() => txtLog.Text, "Error creating account " + username + " - " + wex.Message + System.Environment.NewLine + txtLog.Text);
                }
                catch (Exception ex)
                {
                    lock (unusedemails)
                        emails.Add(email + ':' + emailPassword); //readd our unused email

                    txtLog.SetPropertyThreadSafe(() => txtLog.Text, "Error creating account " + username + " - " + ex.Message + System.Environment.NewLine + txtLog.Text);
                }
            }//foreach account
            threadsRunning--;
            creatorThreadsRunning--;
            lblThreadsRunning.SetPropertyThreadSafe(() => lblThreadsRunning.Text, Convert.ToString(threadsRunning));
            lblCreatorThreadsRunning.SetPropertyThreadSafe(() => lblCreatorThreadsRunning.Text, Convert.ToString(creatorThreadsRunning));
            resetEvents[index].Set(); //signal the thread is done working
        }