예제 #1
0
파일: Page.cs 프로젝트: kiichi54321/Rawler
        protected bool ReadPage(string url)
        {
            var client = GetWebClient();

            parameterList.Clear();
            httpHeaderList.Clear();
            BeforeTrees.Run(this, GetText());

            if (InputParameterTree != null)
            {
                RawlerBase.GetText(GetText(), InputParameterTree, this);
            }

            if (MethodType == Tool.MethodType.GET)
            {
                this.text = client.HttpGet(url, parameterList, httpHeaderList);
            }
            else if (MethodType == Tool.MethodType.POST)
            {
                this.text = client.HttpPost(url, parameterList, httpHeaderList);
            }

            this.currentUrl = url;
            this.pastUrl    = this.currentUrl;

            if (this.Text.Length > 0)
            {
                return(true);
            }
            else
            {
                if (client.ErrMessage != null && (client.ErrMessage.Contains("503") || client.ErrMessage.Contains("500")))
                {
                    ReportManage.ErrReport(this, $"{client.ErrMessage} {url}の読み込みに失敗しました。");
                }
                else
                {
                    if (visbleErr)
                    {
                        ReportManage.ErrReport(this, url + "の読み込みに失敗しました。");
                    }
                    if (ErrorEvent != null)
                    {
                        ErrorEvent(this, new EventArgs());
                    }
                    if (ErrEventTree != null)
                    {
                        ErrEventTree.SetParent();
                        Document d = new Document()
                        {
                            TextValue = client.ErrMessage
                        };
                        d.SetParent(this);
                        d.AddChildren(ErrEventTree);
                        d.Run();
                    }
                }
                return(false);
            }
        }
예제 #2
0
        public override void Run(bool runChildren)
        {
            parameterList.Clear();
            if (BeforeTrees.Any())
            {
                foreach (var item in BeforeTrees)
                {
                    RawlerBase.GetText(GetText(), item, this);
                }
            }

            string url;

            if (string.IsNullOrEmpty(Url))
            {
                url = GetText();
            }
            else
            {
                url = Url;
            }

            url = url + "?" + parameterList.Select(n => $"{Uri.EscapeUriString( n.Key)}={Uri.EscapeUriString(n.Value)}").JoinText("&");

            SetText(url);
            base.Run(runChildren);
        }