Example #1
0
        public override void BeginWork()
        {
            base.BeginWork();

            // 参数设定
            PageUrl  = GetParm("PageUrl"); // 若使用 new Uri() 会把 urlencode 的参数自动 decode
            PageType = GetParm("PageType");
            ImgType  = GetParm("ImgType");
            CollType = GetParm("CollType");

            // 下载页面
            LogInfo("开始下载:" + PageUrl);

            // 选择页面格式
            Dictionary <string, string> headers = new Dictionary <string, string> {
            };
            Encoding encoding = Encoding.GetEncoding("UTF-8");

            if (PageType.Equals("Alibaba"))
            {
                // 获取 Cookie
                var cgSettings = new NacollectorUtils.Settings.CookieGetterSettings
                {
                    StartUrl  = "https://login.1688.com/member/signin.htm?from=sm&Done=" + HttpUtility.UrlEncode(PageUrl),
                    EndUrlReg = @"^" + PageUrl.Substring(0, PageUrl.IndexOf("?")),
                    Caption   = "登录 1688",
                };
                cgSettings.UseInputAutoComplete(@"^https://login\.1688.com/member/signin\.htm", new List <string>()
                {
                    "#TPL_username_1", "#TPL_password_1"
                });
                // ... Show Dialog Working
                string alibabaCookieStr = GetSpiderSettings().CrBrowserCookieGetter(cgSettings);
                if (string.IsNullOrEmpty(alibabaCookieStr))
                {
                    throw new Exception("Cookie 获取未成功");
                }

                encoding = Encoding.GetEncoding("gb2312");
                headers.Add("cookie", alibabaCookieStr);
            }

            var downloadPage = Utils.GetPageByUrl(PageUrl, headers, null, encoding);

            if (downloadPage.StatusCode != System.Net.HttpStatusCode.OK)
            {
                throw new Exception("下载失败 [" + downloadPage.StatusCode + "] " + downloadPage.StatusDescription);
            }
            pageContent = downloadPage.Html;
            LogSuccess("下载完毕");
            pageDom = CQ.CreateDocument(pageContent);

            // 调用指定方法
            this.GetType().GetMethod(PageType + ImgType, BindingFlags.NonPublic | BindingFlags.Instance).Invoke(this, new object[] { });

            // 显示&采集
            AfterGetImgUrl();
        }
        private int maxErrorThreshold     = 5;                   // 最多错误阈值

        public override void BeginWork()
        {
            base.BeginWork();

            // 参数设定
            if (DeleteBeginPage <= 0 || DeleteEndPage <= 0 || DeleteBeginPage > DeleteEndPage)
            {
                throw new Exception("老铁,你输入的参数是什么鬼?");
            }

            // 获取 Cookie
            var cgSettings = new NacollectorUtils.Settings.CookieGetterSettings
            {
                StartUrl  = "https://qudao.gongxiao.tmall.com/supplier/user/invitation_list.htm",
                EndUrlReg = @"^(https|http)://qudao\.gongxiao\.tmall\.com/supplier/user/invitation_list\.htm",
                Caption   = "登录天猫供销平台",
            };

            cgSettings.UseInputAutoComplete(@"^https://login\.taobao\.com/member/login\.jhtml", new List <string>()
            {
                "#TPL_username_1", "#TPL_password_1"
            });
            // ... Show Dialog Working
            cookieStr = CrBrowserCookieGetter(cgSettings);
            if (string.IsNullOrEmpty(cookieStr))
            {
                throw new Exception("Cookie 获取未成功");
            }
            Log("\n");
            // 执行撤回操作

            int totalPage = DeleteEndPage - DeleteBeginPage + 1;

            for (int i = DeleteBeginPage; i <= DeleteEndPage; i++)
            {
                Log($"&gt;&gt; 准备撤回第 {i} 页所有卖家,共 {totalPage} 页,还剩 {totalPage - i} 页");
                try
                {
                    WorkOnPage(i);
                }
                catch (Exception e)
                {
                    if (e.Message == "_END_TASK_")
                    {
                        throw new Exception("撤回失败过多,任务中止执行");
                    }
                    else
                    {
                        LogError(e.Message);
                    }
                }
                Log("\n");
            }
        }
Example #3
0
        int maxErrorThreshold     = 5;                   // 最多错误阈值

        public override void BeginWork()
        {
            base.BeginWork();
            // 参数设定
            SellerId    = GetParm("SellerId").Trim();
            SellerIdArr = SellerId.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.RemoveEmptyEntries);
            if (SellerIdArr.Length <= 0)
            {
                throw new Exception("卖家ID不能一个也没有啊");
            }
            // 获取 Cookie
            var cgSettings = new NacollectorUtils.Settings.CookieGetterSettings
            {
                StartUrl  = "https://qudao.gongxiao.tmall.com/supplier/user/invitation_list.htm",
                EndUrlReg = @"^(https|http)://qudao\.gongxiao\.tmall\.com/supplier/user/invitation_list\.htm",
                Caption   = "登录天猫供销平台",
            };

            cgSettings.UseInputAutoComplete(@"^https://login\.taobao\.com/member/login\.jhtml", new List <string>()
            {
                "#TPL_username_1", "#TPL_password_1"
            });
            // ... Show Dialog Working
            cookieStr = GetSpiderSettings().CrBrowserCookieGetter(cgSettings);
            if (string.IsNullOrEmpty(cookieStr))
            {
                throw new Exception("Cookie 获取未成功");
            }
            // 获取 _tb_token_
            var    homePageUrl  = "https://qudao.gongxiao.tmall.com/supplier/user/invitation_list.htm";
            string homePageHtml = ReqByUrl(homePageUrl);

            LogSuccess($"{homePageUrl} 下载完毕");
            _tb_token_ = new Regex("(?smi)name=(?:\"|')_tb_token_(?:\"|') type=(?:\"|')hidden(?:\"|') value=(?:\"|')(.*?)(?:\"|')").Match(homePageHtml).Groups[1].Value;
            if (string.IsNullOrEmpty(_tb_token_))
            {
                throw new Exception("_tb_token_ 获取失败");
            }
            LogSuccess($"已获取 _tb_token_ = {_tb_token_}");
            Log("\n");
            // 执行邀请操作
            var index = 0;

            foreach (var entry in SellerIdArr)
            {
                if (maxErrorThreshold != 0 && errorSeller.Count >= maxErrorThreshold)
                {
                    if (MessageBox.Show($"邀请失败次数已满 {maxErrorThreshold} 次" + Environment.NewLine + "是否中止任务?", this.GetType().ToString(), MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        throw new Exception("邀请失败过多,任务中止执行");
                    }
                    else
                    {
                        maxErrorThreshold = 0;
                    }
                }

                Log($"&gt;&gt; 准备邀请第 {index+1} 个卖家,共 {SellerIdArr.Count()} 个,还剩 {SellerIdArr.Count() - (index+1)} 个");
                string sellerId = entry.ToString();
                try
                {
                    InviteSellerOnce(sellerId);
                }
                catch (Exception e)
                {
                    LogError(e.Message);
                    errorSeller.Add(sellerId);
                }
                Log("\n");
                index++;
            }
            LogInfo($"共邀请 {SellerIdArr.Count()} 个卖家,成功邀请 {SellerIdArr.Count() - errorSeller.Count} 个,邀请失败 {errorSeller.Count} 个");
        }
Example #4
0
        public override void BeginWork()
        {
            base.BeginWork();

            // 选择页面格式
            Dictionary <string, string> headers = new Dictionary <string, string> {
            };
            Encoding encoding = Encoding.GetEncoding("UTF-8");

            // 淘宝天猫手机端采集
            if (PageType.Equals("TaobaoMobile"))
            {
                // 直接下一步,不下载初始页
                NextStep();
                return;
            }

            // 阿里巴巴获取 Cookie 再采集
            if (PageType.Equals("Alibaba"))
            {
                // 获取 Cookie
                var cgSettings = new NacollectorUtils.Settings.CookieGetterSettings
                {
                    StartUrl  = "https://login.1688.com/member/signin.htm?from=sm&Done=" + HttpUtility.UrlEncode(PageUrl),
                    EndUrlReg = @"^" + PageUrl.Substring(0, PageUrl.IndexOf("?")),
                    Caption   = "登录 1688",
                };
                cgSettings.UseInputAutoComplete(@"^https://login\.1688.com/member/signin\.htm", new List <string>()
                {
                    "#TPL_username_1", "#TPL_password_1"
                });
                // ... Show Dialog Working
                string alibabaCookieStr = CrBrowserCookieGetter(cgSettings);
                if (string.IsNullOrEmpty(alibabaCookieStr))
                {
                    throw new Exception("Cookie 获取未成功");
                }

                encoding = Encoding.GetEncoding("gb2312");
                headers.Add("cookie", alibabaCookieStr);
            }

            // 手机端修改 UA
            if (PageType.EndsWith("Mobile"))
            {
                headers.Add("user-agent", MobileUA);
            }

            // 下载页面
            LogInfo("开始下载:" + PageUrl);

            var downloadPage = Utils.GetPageByUrl(PageUrl, headers, null, encoding);

            if (downloadPage.StatusCode != System.Net.HttpStatusCode.OK)
            {
                throw new Exception("下载失败 [" + downloadPage.StatusCode + "] " + downloadPage.StatusDescription);
            }
            pageContent = downloadPage.Html;
            LogSuccess("下载完毕");
            pageDom = CQ.CreateDocument(pageContent);

            NextStep();
        }