Exemple #1
0
        public List <ShopItemInfo> GetItemsFromCategory(string category, CookieContainer cookies, ProxyInfo proxyInfo)
        {
            string categoryURL = "http://www.supremenewyork.com/shop/all/" + category;
            string pageHTML    = WebTools.GetPageHTML(categoryURL, cookies, proxyInfo).ToLower();

            //<a class="name-link" href="/shop/sweatshirts/w1lxfbkgv/inh4q21pg">Split Crewneck Sweatshirt</a></h1>
            //<p><a class="name-link" href="/shop/sweatshirts/w1lxfbkgv/inh4q21pg">Brown</a>
            string RegExString = "<a class=\"name-link\" href=\"(/[- / a-z 0-9 _]*)\">(.*?)</a></h1>";

            RegExString += "<p><a class=\"name-link\" href=\"[- / a-z 0-9 _]*\">(.*?)</a>";

            Regex               regExpPattern = new Regex(RegExString);
            MatchCollection     allMatches    = regExpPattern.Matches(pageHTML);
            List <ShopItemInfo> items         = new List <ShopItemInfo>();

            foreach (var match in allMatches)
            {
                Match m = (Match)match;
                //Console.WriteLine(m.Groups[1].ToString() + " " +  m.Groups[2].ToString() + " " + m.Groups[3].ToString());
                items.Add(new ShopItemInfo(m.Groups[1].ToString(), m.Groups[2].ToString(), m.Groups[3].ToString()));
            }
            return(items);
        }
Exemple #2
0
        // Adds item to cart, stores cookies in TaskInfo,
        // those cookies have informations about items
        // that are put in cart
        // returns false if failed
        private bool addToCart(ShopItemInfo itemInfo, TaskInfo ti, TaskItemInfo tii)
        {
            forwardMessageToLogMonitor(Properties.Resources.logAdding + " " + itemInfo.name + " " + Properties.Resources.logToCart, ti.name);
            SupremeParser parser = new SupremeParser();

            // get url of the chosen item
            var itemUrl = "http://www.supremenewyork.com" + itemInfo.url;

            ti.lastItemUri = itemUrl; // referer for checkout
            var responseItemHTML = WebTools.GetPageHTML(itemUrl, cookies[ti.name], (ProxyInfo)infoManager.GetProxyByName(ti.proxyName));

            string itemAddUrl = "https://www.supremenewyork.com" + parser.GetItemCartAddUrl(responseItemHTML);

            String style = parser.GetItemStyleId(responseItemHTML, tii);
            String size  = parser.GetItemSizeIdFromPage(responseItemHTML, tii);

            String csrf_token = new Regex("<meta name=\"csrf-token\" content=\"([^\"]*)\"").Match(responseItemHTML).Groups[1].Value;


            //FileLogger.log("ItemUri: " + itemUrl + "\n");
            //FileLogger.log("Style: " + style + " Size: " + size + "\n");
            //FileLogger.log("PostUri: " + itemAddUrl + "\n");

            if (style == null || size == null)
            {
                forwardMessageToLogMonitor(Properties.Resources.logItemNotAvailable, ti.name);
                return(false);
            }
            string postString = PostStringGenerator.generateAddCartPostString(size, style);

            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(itemAddUrl);

            req.Referer = itemUrl;
            req.Method  = "POST";
            req.Accept  = "*/*;q=0.5, text/javascript, application/javascript, application/ecmascript, application/x-ecmascript";
            req.Headers["x-csrf-token"] = csrf_token;
            req.ContentType             = "application/x-www-form-urlencoded; charset=UTF-8"; // utf8 del
            req.ContentLength           = postString.Length;
            req.CookieContainer         = cookies[ti.name];

            WebTools.setProxy((ProxyInfo)infoManager.GetProxyByName(ti.proxyName), req);

            // as postWriter doesn't actually send any data, we only need to make sure that GetResponse is going good.
            StreamWriter postWriter = new StreamWriter(req.GetRequestStream());

            postWriter.Write(postString);
            postWriter.Close();


            //MSDOC
            //The GetResponse method sends a request to an Internet resource and returns a WebResponse instance.
            //If the request has already been initiated by a call to GetRequestStream, the GetResponse method
            //completes the request and returns any response. \|/
            var res = WebTools.SendRequestAtAllCosts(req);

            res.Close();
            // it takes ~7ms to read the response, but well, we don't need it here, we just need cookiez

            foreach (var cookie in cookies[ti.name].GetCookies(new Uri("http://www.supremenewyork.com")))
            {
                Console.WriteLine(cookie.ToString());
            }


            //cookies are now in CookieContainer which is a reference for cookies[ti.number] ( no need to save them )
            forwardMessageToLogMonitor(Properties.Resources.logSuccessfullyAdded + " " + itemInfo.name + " " + Properties.Resources.logToCart, ti.name);
            return(true);
        }