示例#1
0
        public bool Login(string sfAcc, string sfPass)
        {
            web        = new CustomWeb();
            this.SFAcc = sfAcc;
            string url = "https://manager.sunfrogshirts.com/Login.cfm";
            NameValueCollection nvc = new NameValueCollection();

            nvc.Add("username", sfAcc);
            nvc.Add("password", sfPass);

            string result = web.SendRequest(url, "POST", nvc, true, "application/x-www-form-urlencoded");

            if (!string.IsNullOrEmpty(result))
            {
                var doc = new HtmlAgilityPack.HtmlDocument();
                doc.LoadHtml(result);
                try
                {
                    string aff = doc.DocumentNode.SelectSingleNode("//a[@id='showAffiliateID']")
                                 .SelectSingleNode(".//strong[@class='clearfix']").InnerText.Trim().Replace("?", "");
                    if (aff != null)
                    {
                        AM = aff;
                    }
                }
                catch
                {
                }
            }
            return(IsLoggedIn(result));
        }
示例#2
0
        public RequestController()
        {
            //UserAgentTool tool = new UserAgentTool();
            //string redirectUrl = string.Empty;
            //var agent = tool.RandomUserAgent("desktop", "windows", "browser", new string[] { "chrome", "firefox", "safari" });
            //Console.WriteLine("full: "+ agent);
            //CustomWeb web = new CustomWeb(agent.agent_string);
            //string result = web.SendRequest("https://www.facebook.com/help/", "GET", "www.facebook.com", null, ref redirectUrl, false, true);
            //Thread.Sleep(5000);
            //result = web.SendRequest("https://www.facebook.com/help/", "GET", "www.facebook.com", null, ref redirectUrl, false, false);
            //Thread.Sleep(5000);
            //NameValueCollection nvc = new NameValueCollection();
            ////[email protected]|xpadxjh5nt1987
            //nvc.Add("email", "*****@*****.**");
            //nvc.Add("pass", "bangtuoc@123");


            //redirectUrl = string.Empty;
            //result = web.SendRequest("https://www.facebook.com/login.php?login_attempt=1", "POST",
            //    "www.facebook.com", nvc, ref redirectUrl, true, false, "application/x-www-form-urlencoded");

            //Console.WriteLine("login result: "+ redirectUrl);
            //if(!redirectUrl.Contains("checkpoint"))
            //{
            //    result = web.SendRequest("https://www.facebook.com/", "GET", "www.facebook.com", null, ref redirectUrl, false, false);
            //}

            //Console.WriteLine("terst");
            web = new CustomWeb();
        }
示例#3
0
        private void button2_Click(object sender, EventArgs e)
        {
            CustomWeb web        = new CustomWeb();
            string    testUrl    = "https://www.teepublic.com/";
            string    testResult = web.SendRequest(testUrl, "GET", null, true);
            //Console.WriteLine(testResult);

            NameValueCollection nvc = new NameValueCollection();

            nvc.Add("utf8", "✓");
            nvc.Add("user[post_login_partial]", "");
            nvc.Add("session[email]", "*****@*****.**");
            nvc.Add("session[password]", "19001560");
            nvc.Add("session[remember_me]", "1");
            nvc.Add("commit", "Login");
            string url = "https://www.teepublic.com/users/sign_in";

            string result = web.SendRequest(url, "POST", "www.teepublic.com", nvc, false, "application/x-www-form-urlencoded");

            Console.WriteLine(result);
        }
        public WebRequest()
        {
            string result  = string.Empty;
            int    onCount = 3;

            while (onCount > 0)
            {
                onCount--;
                customWeb = new CustomWeb();

                if (string.IsNullOrEmpty(API.api_key))
                {
                    NameValueCollection nameValueCollection = new NameValueCollection();
                    nameValueCollection.Add("PrivateKey", PrivateKey);
                    result = customWeb._Post(API.standart_url + "api", nameValueCollection);
                    if (result.Contains("status\":\"100"))
                    {
                        API.api_key = result.Split(':')[2].TrimEnd('}').Trim('"');
                    }
                }
                else
                {
                    NameValueCollection nameValueCollection = new NameValueCollection();
                    nameValueCollection.Add("key", API.api_key);
                    result = customWeb._Post(API.standart_url + "api", nameValueCollection);

                    if (result.Contains("status\":\"101"))
                    {
                        API.api_key = result.Split(':')[2].TrimEnd('}').Trim('"');
                        customWeb   = new CustomWeb();
                        return;
                    }
                    else
                    {
                        API.api_key = string.Empty;
                    }
                }
            }
            throw new Exception("Error bad create data<LLL>");
        }
        public void LoadProductJson()
        {
            try
            {
                CustomWeb web    = new CustomWeb();
                string    result = web.SendRequest("https://viralstyle.com/design.beta/product-categories?api_campaign=false",
                                                   "GET", "viralstyle.com", null, false);
                result            = "{\"ProductData\":" + result + "}";
                viralStyleProduct = JsonConvert.DeserializeObject <ViralStyleProduct>(result);
                //ViralStyleProductData jsonData = JsonConvert.DeserializeObject<ViralStyleProductData>(result);

                //viralStyleProduct = new ViralStyleProduct();
                //viralStyleProduct.ProductData.Add(jsonData);
                //string rootPath = Directory.GetCurrentDirectory() + "\\";
                //string jsonData = File.ReadAllText(rootPath + Settings.Default.ViralStyle_Product_Path);
                //jsonData = jsonData.Replace("\r\n", "");
                //viralStyleProduct = JsonConvert.DeserializeObject<ViralStyleProduct>(jsonData);
            }
            catch (Exception ex)
            {
                logger.ErrorFormat("Error: {0}, stacktrace: {1}", ex.Message, ex.StackTrace);
            }
        }
示例#6
0
        private void button1_Click(object sender, EventArgs e)
        {
            IWebDriver webDriver = new ChromeDriver();

            webDriver.Navigate().GoToUrl("https://teespring.com/login");

            var divRoot    = webDriver.FindElement(By.XPath("//div[@class='authentication__standalone js-user-auth-standalone authentication--email authentication--login_open']"));
            var divAuth    = divRoot.FindElement(By.XPath("//div[@class='authentication authentication--login js-user-login']"));
            var emailInput = divAuth.FindElement(By.Name("email"));

            DivClick(webDriver, emailInput, "*****@*****.**", 1000);

            var passInput = divAuth.FindElement(By.Name("password"));

            DivClick(webDriver, passInput, "19001560", 1000);

            var loginBtn = divAuth.FindElement(By.XPath("//input[@class='button button--primary authentication__button js-email-login-submit']"));

            loginBtn.Click();
            Thread.Sleep(1500);


            var tag = webDriver.FindElement(By.XPath("//meta[@name='csrf-token']"));

            CookieContainer container = new CookieContainer();

            foreach (var cc in webDriver.Manage().Cookies.AllCookies)
            {
                container.Add(new System.Net.Cookie(cc.Name, cc.Value, cc.Path, cc.Domain));
            }

            CustomWeb web   = new CustomWeb(container);
            string    token = tag.GetAttribute("content");

            web.TOKEN = token;

            //string result = web.SendRequest("https://teespring.com/login", "GET", null, true);
            //var doc = new HtmlAgilityPack.HtmlDocument();
            //doc.LoadHtml(result);
            //var metaNode = doc.DocumentNode.SelectSingleNode("//meta[@name='csrf-token']");
            //token = metaNode.GetAttributeValue("content", string.Empty);
            ////web.TOKEN = token;

            //var htmlWeb = new HtmlAgilityPack.HtmlWeb();
            //doc = htmlWeb.Load("https://teespring.com/login");
            //metaNode = doc.DocumentNode.SelectSingleNode("//meta[@name='csrf-token']");
            //token = metaNode.GetAttributeValue("content", string.Empty);
            ////web.TOKEN = token;

            //string url = "https://teespring.com/sessions";
            NameValueCollection nvc = new NameValueCollection();
            //nvc.Add("email", "*****@*****.**");
            //nvc.Add("password", "19001560");

            //string result = web.SendRequest(url, "POST", nvc, false, "application/x-www-form-urlencoded");

            //Console.WriteLine("login: "******"csrftoken", token, "/", "teespring.com"));
            //Console.WriteLine("result: "+result);

            string responseUrl = "";
            string result      = web.SendRequest("https://teespring.com/designs", "GET", null, ref responseUrl);

            Console.WriteLine("response url: " + responseUrl);

            // signed request
            string imageName = RandomStringOnly(8) + ".png";
            string signedUrl = "https://teespring.com/designs/sign_s3?s3_object_type=image/png&s3_object_name=" + imageName;

            result = web.SendRequest(signedUrl, "GET", null);
            Console.WriteLine("signed url: " + result);
            SignedResponse signedRes = JsonConvert.DeserializeObject <SignedResponse>(result);

            Console.WriteLine(signedUrl);

            // regist 1 signal
            string sign1Url = WebUtility.UrlDecode(signedRes.signed_request);

            Console.WriteLine(sign1Url);
            nvc.Clear();
            string tempUrl = sign1Url.Split('?')[1];

            string[] temp2 = tempUrl.Split('&');
            //nvc.Add("X-Amz-Algorithm", temp2[0].Replace("X-Amz-Algorithm=", ""));
            //nvc.Add("X-Amz-Credential", temp2[1].Replace("X-Amz-Algorithm=", ""));
            //nvc.Add("X-Amz-Date", temp2[2].Replace("X-Amz-Algorithm=", ""));
            //nvc.Add("X-Amz-Expires", temp2[3].Replace("X-Amz-Algorithm=", ""));
            //nvc.Add("X-Amz-SignedHeaders", temp2[4].Replace("X-Amz-Algorithm=", ""));
            //nvc.Add("x-amz-acl", temp2[5].Replace("X-Amz-Algorithm=", ""));
            //nvc.Add("X-Amz-Signature", temp2[6].Replace("X-Amz-Algorithm=", ""));
            nvc.Add("PNG",
                    ImageToBase64(Image.FromFile(@"D:\Auto\Logo\test.png"),
                                  System.Drawing.Imaging.ImageFormat.Png));
            result = web.SendCustomRequest(sign1Url, "OPTIONS", "teespring-usercontent.s3.amazonaws.com", null, true, "PUT");
            result = web.SendCustomRequest2(sign1Url, "PUT", "teespring-usercontent.s3.amazonaws.com", @"D:\Auto\Logo\test.png", false, "", false, "image/png");
            // result = web.SendCustomRequest(sign1Url, "POST", "teespring-usercontent.s3.amazonaws.com", null);
            Console.WriteLine("sign1url result: " + result);
            string uploadUrl = responseUrl.Replace("edit", "uploads");

            // string uploadImageUrl = "https://teespring.com/designs/lu32t4/uploads";
            string randName = RandomStringOnly(8);
            //LogoModel logo = new LogoModel(@"D:\Auto\Logo\1.png", "png");
            LogoModel logo = new LogoModel(imageName, "png");

            result = web.HttpUploadFileByJson(uploadUrl, JsonConvert.SerializeObject(logo));
            Console.WriteLine(result);


            // check valid url
            string title    = "this-is-ultimate-113";
            string checkUrl = "https://teespring.com/url/availability?url=" + title;

            result = web.SendCustomRequest(checkUrl, "GET", "teespring.com", null);
            Console.WriteLine("check url result: " + result);


            // put upload design
            string uploadDesignUrl = responseUrl.Replace("/edit", "");
            string lookupId        = uploadDesignUrl.Substring(uploadDesignUrl.LastIndexOf("/") + 1);
            //UploadDesignParameters desginParams = new UploadDesignParameters(lookupId, title.Replace("-", " "),
            //    title, "I will write some description on here!", "#ipshirt", imageName,
            //    "https://teespring-usercontent.s3.amazonaws.com/"+ imageName, "test.png");

            DesignParameter designs = new DesignParameter(lookupId, title.Replace("-", " "),
                                                          title, "I will write some description on here!", "#ipshirt", imageName,
                                                          "https://teespring-usercontent.s3.amazonaws.com/" + imageName, "test.png");


            string uploadResult = web.SendCustomRequest(uploadDesignUrl, "PUT", "teespring.com",
                                                        designs.ConvertToNVC(), false, "", false, "application/x-www-form-urlencoded", "application/json");

            //dynamic uploadResult = web.SendRequestWithStringData(uploadDesignUrl, "PUT", "teespring.com",
            //   desginParams.ToString(), false, "", false, "application/json");
            Console.WriteLine("upload reuslt: " + uploadResult);
            // camp id
            dynamic dResult = JsonConvert.DeserializeObject(uploadResult);
            string  campId  = dResult.campaign_id;
            // launch campaign
            string  launchUrl    = string.Format("https://teespring.com/campaigns/{0}/launch", campId);
            dynamic launchResult = web.SendRequestWithStringData(launchUrl, "POST", "teespring.com",
                                                                 "partnership=", false, "", false, "application/x-www-form-urlencoded; charset=UTF-8");
            //Console.WriteLine(launchResult);
            var doc = new HtmlAgilityPack.HtmlDocument();

            doc.LoadHtml(launchResult);
            var metaNode = doc.DocumentNode.SelectSingleNode("//meta[@name='csrf-token']");

            token     = metaNode.GetAttributeValue("content", string.Empty);
            web.TOKEN = token;

            string url = "https://teespring.com/sessions";

            nvc.Clear();
            nvc.Add("email", "*****@*****.**");
            nvc.Add("password", "19001560");

            result = web.SendRequest(url, "POST", nvc, false, "application/x-www-form-urlencoded");


            Console.WriteLine("login2 : " + result);

            launchResult = web.SendRequestWithStringData(launchUrl, "POST", "teespring.com",
                                                         "partnership=", false, "", false, "application/x-www-form-urlencoded; charset=UTF-8");

            string readyUrl = "https://teespring.com/designs/" + lookupId + "/assets_ready";
            //for (int i = 0; i < 5; i++)
            //{
            string finalResult = web.SendRequest(readyUrl, "GET", null);

            Console.WriteLine(finalResult);
            Thread.Sleep(2000);
            //}
        }
示例#7
0
 public SunfrogController()
 {
     web = new CustomWeb();
 }
 public ViralStyleController()
 {
     web = new CustomWeb();
 }
示例#9
0
        private void button1_Click(object sender, EventArgs e)
        {
            CustomWeb           web = new CustomWeb();
            NameValueCollection nvc = new NameValueCollection();

            string url = "https://viralstyle.com/design.beta/product-categories?api_campaign=false";

            string result = web.SendRequest(url, "GET", "viralstyle.com", null, true);

            //Console.WriteLine(result);
            url = "https://viralstyle.com/api/v2/token";

            nvc.Clear();
            //grant_type=client_credentials&client_id=frontend&client_secret=frontend&scope=public
            nvc.Add("grant_type", "client_credentials");
            nvc.Add("client_id", "frontend");
            nvc.Add("client_secret", "frontend");
            nvc.Add("scope", "public");
            result = web.SendRequest(url, "POST", "viralstyle.com", nvc, false, "application/x-www-form-urlencoded");
            dynamic jsonResult = JsonConvert.DeserializeObject(result);
            string  token      = jsonResult.access_token;

            Console.WriteLine(token);

            //nvc.Add("email", "*****@*****.**");
            // nvc.Add("password", "19001560");
            string loginUrl = " https://viralstyle.com/api/v2/auth/login";

            LoginModel loginModel = new LoginModel("*****@*****.**", "19001560", false);
            string     loginJson  = JsonConvert.SerializeObject(loginModel);

            result = web.SendRequestJsonType(loginUrl, "POST", "application/json", loginJson, token, true);
            // Console.WriteLine(result);

            url = "https://viralstyle.com/api/v2/token";
            nvc.Clear();
            //grant_type=client_credentials&client_id=frontend&client_secret=frontend&scope=public
            nvc.Add("grant_type", "client_credentials");
            nvc.Add("client_id", "frontend");
            nvc.Add("client_secret", "frontend");
            nvc.Add("scope", "public");
            result     = web.SendRequest(url, "POST", "viralstyle.com", nvc, false, "application/x-www-form-urlencoded");
            jsonResult = JsonConvert.DeserializeObject(result);
            token      = jsonResult.access_token;
            Console.WriteLine(token);

            string uploadUrl = "https://viralstyle.com/design.beta/upload-asset";

            nvc.Clear();
            //nvc.Add("is_api_order", "0");
            nvc.Add("product_id", "1");
            nvc.Add("is_embroidery", "0");
            nvc.Add("is_phone_case", "0");
            nvc.Add("sublimation", "0");
            nvc.Add("campaign_identifier", "NEW");
            nvc.Add("identifier", "NEW");
            nvc.Add("sublimation", "0");
            nvc.Add("width", "218");
            nvc.Add("extension", "png");
            result = web.HttpUploadFile(uploadUrl, @"C:\Users\RAVI\Desktop\Logo\BROWN.png",
                                        "image_file", "image/png", nvc);
            dynamic uploadResult = JsonConvert.DeserializeObject(result);
            string  campId       = uploadResult.data.campaign_identifier;
            string  imageId      = Path.GetFileNameWithoutExtension(uploadResult.data.original_file.ToString());
            string  id           = uploadResult.data.identifier;

            string orgUrl     = uploadResult.data.original_file;
            string resizeUrl  = uploadResult.data.trimmed_image;
            string trimmedUrl = uploadResult.data.resized_image;

            Console.WriteLine(result);


            string title       = "this is my title";
            string description = "this is another description";
            // string token = "tkMyMmQDXpeeLkFaLv5wb3lPx0KdEsNV269PnepU";
            string uniqueCampUrl = "here-is-my-url-" + StringUtil.RandomString(8);
            string jsonData      = File.ReadAllText(Directory.GetCurrentDirectory() + "\\data3.json");

            nvc.Clear();
            result = web.SendRequest("https://viralstyle.com/design.beta", "GET", nvc);
            var doc = new HtmlAgilityPack.HtmlDocument();

            doc.LoadHtml(result);

            string newToken = doc.DocumentNode.SelectSingleNode("//input[@id='_token']")
                              .GetAttributeValue("value", string.Empty);

            System.Drawing.Image img = System.Drawing.Image.FromFile(@"C:\Users\RAVI\Desktop\Logo\test.png");
            //var resizeImg = Resize(@"C:\Users\RAVI\Desktop\Logo\BROWN.png", 0.5);
            string base64String;

            using (var ms = new MemoryStream())
            {
                img.Save(ms, img.RawFormat);
                base64String = "data:image/png;base64," + Convert.ToBase64String(ms.ToArray());
            }
            //img.Dispose();
            img.Dispose();
            jsonData = jsonData.Replace("{CAMP_ID}", campId)
                       .Replace("{IMAGE_ID}", id)
                       .Replace("{RESIZE_IMAGE_URL}", resizeUrl)
                       .Replace("{TRIMMED_IMAGE_URL}", trimmedUrl)
                       .Replace("{ORG_IMAGE_URL}", orgUrl)
                       .Replace("{TITLE}", title)
                       .Replace("{DESCRIPTION}", description)
                       .Replace("{CAMP_URL}", uniqueCampUrl)
                       .Replace("{TOKEN}", newToken)
                       .Replace("{IMAGE_64}", base64String);


            // check url
            dynamic urlObj = new ExpandoObject();

            urlObj.url = uniqueCampUrl;
            string checkResult = web.HttpUploadFileByJson("https://viralstyle.com/design.beta/check-url",
                                                          JsonConvert.SerializeObject(urlObj), token, newToken);
            //Console.WriteLine(result);
            string campUrl = "https://viralstyle.com/api/v2/designer/store";

            result = web.HttpUploadFileByJson(campUrl, jsonData, token, newToken);
            Console.WriteLine(result);
        }
示例#10
0
 public CafepressController()
 {
     web = new CustomWeb();
 }
示例#11
0
        private void button1_Click(object sender, EventArgs e)
        {
            NameValueCollection nvc = new NameValueCollection();
            CustomWeb           web = new CustomWeb();


            string test = web.SendRequest("https://www.teepublic.com", "GET", null, true, "");

            string loginUrl = "https://www.teepublic.com/users/sign_in";

            nvc.Clear();
            nvc.Add("utf8", "✓");
            nvc.Add("user[post_login_partial]", "");
            nvc.Add("session[email]", "*****@*****.**");
            nvc.Add("session[password]", "19001560");
            nvc.Add("session[remember_me]", "0");
            nvc.Add("commit", "Login");


            //https://www.teepublic.com/users/sign_up
            test = web.SendRequest("https://www.teepublic.com/users/sign_up", "GET", null, false, "");
            string responseUrl = "";
            string result      = web.SendRequest(loginUrl, "POST", "www.teepublic.com", nvc, ref responseUrl, true, "application/x-www-form-urlencoded; charset=UTF-8");

            test = web.SendRequest("https://www.teepublic.com", "GET", null, false, "");

            result = web.SendRequest("https://www.teepublic.com/design/quick_create", "GET",
                                     "www.teepublic.com", null, ref responseUrl, false, "");
            //Console.WriteLine(result);

            string referer  = responseUrl;
            string publicId = "";

            string tempUrl = "";

            result = web.SendRequest(referer, "GET",
                                     "www.teepublic.com", null, ref tempUrl, false, "");


            var doc = new HtmlAgilityPack.HtmlDocument();

            doc.LoadHtml(result);

            var     fileInput = doc.DocumentNode.SelectSingleNode("//input[@name='file']");
            string  uploadUrl = fileInput.GetAttributeValue("data-url", string.Empty);
            dynamic objData   = JsonConvert.DeserializeObject(fileInput.GetAttributeValue("data-form-data",
                                                                                          string.Empty).Replace("&quot;", "\"").Replace("{{", "{").Replace("}}", "}"));

            //result = web.SendUploadOptionRequest(uploadUrl,
            //    "OPTIONS", referer);

            nvc.Clear();
            nvc.Add("callback", objData.callback.ToString());
            nvc.Add("eager", objData.eager.ToString());
            nvc.Add("exif", objData.exif.ToString());
            nvc.Add("folder", objData.folder.ToString());
            nvc.Add("format", objData.format.ToString());
            nvc.Add("image_metadata", objData.image_metadata.ToString());
            nvc.Add("invalidate", objData.invalidate.ToString());
            nvc.Add("public_id", objData.public_id.ToString());
            nvc.Add("timestamp", objData.timestamp.ToString());
            nvc.Add("transformation", objData.transformation.ToString());
            nvc.Add("type", objData.type.ToString());
            nvc.Add("signature", objData.signature.ToString());
            nvc.Add("api_key", objData.api_key.ToString());

            result = web.HttpUploadFile(uploadUrl, @"C:\Users\RAVI\Desktop\Logo\SMITH.png",
                                        "file", "image/png", nvc, "api.cloudinary.com", "https://www.teepublic.com", referer);


            string colorLink = GetLinkFromStr(result).Replace("<a href=\"", "").Replace("\">", "");

            result = web.SendRequest(colorLink, "GET", null, false, "");

            string finalLink = GetLinkFromStr(result).Replace("<a href=\"", "").Replace("\">", "");

            result = web.SendRequest(finalLink, "GET", null, false, "");
            Console.WriteLine(result);

            string updateInfoUrl = referer.Replace("edit", "").Replace("designs", "t-shirt");

            //result = web.SendRequest(updateInfoUrl, "POST",
            // "www.teepublic.com", nvc, ref responseUrl, false, "application/x-www-form-urlencoded");

            result = web.SendUploadInfo(updateInfoUrl, "POST", "www.teepublic.com",
                                        "application/x-www-form-urlencoded", queryString, referer);
            Console.WriteLine(result);
        }
示例#12
0
 private void bgWorker_DoWork(object sender, DoWorkEventArgs e)
 {
     try
     {
         CustomWeb web         = new CustomWeb();
         bool      loginResult = Login(email, pass, web);
         if (loginResult)
         {
             int    pageSize  = 100;
             int    nextIndex = crawlerInfo.CurrentIndex;
             int    counter   = 1;
             string rootPath  = Directory.GetCurrentDirectory() + "\\Links\\";
             if (!Directory.Exists(rootPath))
             {
                 Directory.CreateDirectory(rootPath);
             }
             List <Sunfrog> totalList = new List <Sunfrog>();
             do
             {
                 List <Sunfrog> dataList = new List <Sunfrog>();
                 bool           hasNext  = GetNextLinks(web, ref dataList, nextIndex);
                 if (dataList.Count > 0)
                 {
                     totalList.AddRange(dataList);
                 }
                 DateTime now = DateTime.Now;
                 UpdateText(now.ToString("dd/MM/yyyy HH:mm:ss") + " : current file size: " + totalList.Count);
                 if (hasNext)
                 {
                     nextIndex += pageSize;
                     crawlerInfo.CurrentIndex = nextIndex;
                     //SaveSetting();
                     if (totalList.Count >= Settings.Default.SIZE)
                     {
                         CsvUtil.WriteObjectsToCSV(totalList, rootPath, $"links_{counter++}.csv");
                         totalList.Clear();
                         SaveSetting();
                         UpdateText("clr");
                     }
                     Thread.Sleep(1000 * Settings.Default.DELAY);
                 }
                 else
                 {
                     if (totalList.Count > 0)
                     {
                         // string desPath = rootPath + $"links_{startIndex}.txt";
                         CsvUtil.WriteObjectsToCSV(totalList, rootPath, $"links_{counter++}.csv");
                         totalList.Clear();
                         SaveSetting();
                     }
                     break;
                 }
             } while (true);
         }
         else
         {
             MessageBox.Show("Login failed!");
         }
     }
     catch (Exception ex)
     {
         logger.ErrorFormat($"Error: {ex.Message}, Stack Track: {ex.StackTrace}");
     }
 }
示例#13
0
        public bool GetNextLinks(CustomWeb web, ref List <Sunfrog> dataList, int startIndex = 1)
        {
            try
            {
                //string rootPath = Directory.GetCurrentDirectory() + "\\Links\\";
                //if(!Directory.Exists(rootPath))
                //{
                //    Directory.CreateDirectory(rootPath);
                //}
                string url    = $"https://manager.sunfrogshirts.com/my-art.cfm?start={startIndex}&sortby=1&sortDir=ASC&searchfield=";
                string result = web.SendRequest(url, "GET", null);
                if (!string.IsNullOrEmpty(result))
                {
                    var doc = new HtmlAgilityPack.HtmlDocument();
                    doc.LoadHtml(result);

                    var divParent = doc.DocumentNode.SelectSingleNode("//div[@id='sortable']");
                    if (divParent != null)
                    {
                        // var divs = divParent.SelectNodes(".//div[@class='col-xs-6 col-sm-4 col-md-3']");
                        //  if(divs != null && divs.Count > 0)
                        {
                            dataList = new List <Sunfrog>();
                            var divs = divParent.SelectNodes(".//a[starts-with(@href, 'my-art-edit.cfm?GroupID=')]");
                            foreach (var item in divs)
                            {
                                Sunfrog data = new Sunfrog();
                                //my-art-edit.cfm?GroupID=134983299
                                //var ahref = item.SelectSingleNode(".//a[starts-with(@href, 'my-art-edit.cfm?GroupID=')]");
                                // if(ahref != null)
                                {
                                    string groupLink = item.GetAttributeValue("href", string.Empty);
                                    if (!string.IsNullOrEmpty(groupLink))
                                    {
                                        data.EditLink = "https://manager.sunfrogshirts.com/" + groupLink;
                                    }
                                    var imgTag = item.SelectSingleNode(".//img");
                                    if (imgTag != null)
                                    {
                                        data.ImageLink = imgTag.GetAttributeValue("src", string.Empty);
                                    }
                                }

                                if (!string.IsNullOrEmpty(data.EditLink))
                                {
                                    dataList.Add(data);
                                }
                            }

                            //if(dataList.Count > 0)
                            //{
                            //   // string desPath = rootPath + $"links_{startIndex}.txt";
                            //    CsvUtil.WriteObjectsToCSV(dataList, rootPath, $"links_{startIndex}.csv");

                            //}
                            return(true);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                logger.ErrorFormat($"Error: {ex.Message}, Stack Track: {ex.StackTrace}");
            }

            return(false);
        }
示例#14
0
 public RequestController(string userAgent)
 {
     this.userAgent = userAgent;
     web            = new CustomWeb(userAgent);
 }