Example #1
0
        public static AllDataSheetSearchResult Search(AllDataSheetSearchContext searchContext)
        {
            if (!searchContext.CanLoadMore)
            {
                AllDataSheetSearchResult ret = new AllDataSheetSearchResult();
                ret.Parts         = null;
                ret.SearchContext = searchContext;
                return(ret);
            }

            while (true)
            {
                string         url     = $"{SiteAddress}?Searchword={searchContext.SearchValue}&sPage={searchContext.NextPage}&sField={(int)searchContext.Option}";
                HttpWebRequest request = Requests.CreateDefaultRequest(url);
                request.Referer = searchContext.Referer;
                string result = Requests.ReadResponseString(request);

                HtmlDocument document = new HtmlDocument();
                document.LoadHtml(result);

                if (searchContext.NextPage == 1)
                {
                    int totalPages;
                    AllDataSheetSearchContext.SearchOption option;
                    FilterSearchMode(document, out totalPages, out option);
                    searchContext.TotalPages = totalPages;
                    if (searchContext.Option != option)
                    {
                        if (!searchContext.UsedOptions.Contains(searchContext.Option))
                        {
                            searchContext.UsedOptions.Add(searchContext.Option);
                        }
                        searchContext.Option = option;
                    }
                }

                AllDataSheetSearchResult sret = new AllDataSheetSearchResult();
                if (searchContext.UsedOptions.Contains(searchContext.Option))
                {
                    sret.Parts = new List <AllDataSheetPart>();
                    if (searchContext.CanLoadMore)
                    {
                        searchContext.Next(url);
                        continue;
                    }
                }
                else
                {
                    sret.Parts = FilterResults(document);
                }

                sret.SearchContext = searchContext;
                searchContext.Next(url);

                return(sret);
            }
        }
Example #2
0
        public static AllDataSheetSearchResult Search(string value)
        {
            string         url     = $"{SiteAddress}?Searchword={value}&sPage=1&sField=4";
            HttpWebRequest request = Requests.CreateDefaultRequest(url);
            string         result  = Requests.ReadResponseString(request);

            HtmlDocument document = new HtmlDocument();

            document.LoadHtml(result);

            int totalPages;

            AllDataSheetSearchContext.SearchOption option;
            FilterSearchMode(document, out totalPages, out option);

            AllDataSheetSearchContext searchContext = new AllDataSheetSearchContext(value);

            searchContext.NextPage   = 1;
            searchContext.TotalPages = totalPages;
            if (option != AllDataSheetSearchContext.SearchOption.Match)
            {
                searchContext.UsedOptions.Add(AllDataSheetSearchContext.SearchOption.Match);
                searchContext.Option = option;
            }
            searchContext.Next(url);

            AllDataSheetSearchResult ret = new AllDataSheetSearchResult();

            ret.Parts         = FilterResults(document);
            ret.SearchContext = searchContext;

            return(ret);
        }
        public static AllDataSheetSearchResult Search(string value)
        {
            string url = SiteAddress + "?" + "Searchword=" + value + "&sPage=1&sField=4";
            HttpWebRequest request = Requests.CreateDefaultRequest(url);
            string result = Requests.ReadResponseString(request);

            HtmlDocument document = new HtmlDocument();
            document.LoadHtml(result);

            int totalPages;
            AllDataSheetSearchContext.SearchOption option;
            FilterSearchMode(document, out totalPages, out option);

            AllDataSheetSearchContext searchContext = new AllDataSheetSearchContext(value);
            searchContext.NextPage = 1;
            searchContext.TotalPages = totalPages;
            if (option != AllDataSheetSearchContext.SearchOption.Match)
            {
                searchContext.UsedOptions.Add(AllDataSheetSearchContext.SearchOption.Match);
                searchContext.Option = option;
            }
            searchContext.Next(url);

            AllDataSheetSearchResult ret = new AllDataSheetSearchResult();
            ret.Parts = FilterResults(document);
            ret.SearchContext = searchContext;

            return ret;
        }
        public static AllDataSheetSearchResult Search(AllDataSheetSearchContext searchContext)
        {
            if (!searchContext.CanLoadMore)
            {
                AllDataSheetSearchResult ret = new AllDataSheetSearchResult();
                ret.Parts = null;
                ret.SearchContext = searchContext;
                return ret;
            }

            while (true)
            {
                string url = SiteAddress + "?" + "Searchword=" + searchContext.SearchValue + "&sPage=" + searchContext.NextPage + "&sField=" + (int)searchContext.Option;
                HttpWebRequest request = Requests.CreateDefaultRequest(url);
                request.Referer = searchContext.Referer;
                string result = Requests.ReadResponseString(request);

                HtmlDocument document = new HtmlDocument();
                document.LoadHtml(result);

                if (searchContext.NextPage == 1)
                {
                    int totalPages;
                    AllDataSheetSearchContext.SearchOption option;
                    FilterSearchMode(document, out totalPages, out option);
                    searchContext.TotalPages = totalPages;
                    if (searchContext.Option != option)
                    {
                        if (!searchContext.UsedOptions.Contains(searchContext.Option)) searchContext.UsedOptions.Add(searchContext.Option);
                        searchContext.Option = option;
                    }
                }

                AllDataSheetSearchResult sret = new AllDataSheetSearchResult();
                if (searchContext.UsedOptions.Contains(searchContext.Option))
                {
                    sret.Parts = new List<AllDataSheetPart>();
                    if (searchContext.CanLoadMore)
                    {
                        searchContext.Next(url);
                        continue;
                    }
                }
                else
                {
                    sret.Parts = FilterResults(document);
                }

                sret.SearchContext = searchContext;
                searchContext.Next(url);

                return sret;
            }
        }