protected override string GetUrl(SearchCategory scLocation, SearchCategory scCategory, string keyword, int pageNum)
        {
            string text  = scLocation.Url;
            string url   = scCategory.Url;
            string text2 = url.Split(new char[]
            {
                '/'
            }).LastOrDefault <string>();
            string text3 = string.Empty;

            text = UrlDownloader.UrlEncode(text);
            string text4 = scLocation.Meta ?? string.Empty;

            if (!string.IsNullOrEmpty(keyword))
            {
                text2 += UrlDownloader.UrlEncode(string.Format(" {0}", keyword));
            }
            string a;

            if ((a = text4) != null)
            {
                if (a == "canada")
                {
                    this.country = AbstractScraper.Country.Canada;
                    text3        = string.Format("http://ca.local.yahoo.com/results?csz={0}&stx={1}&pg_nm={2}", text.Replace("/", "+"), text2, pageNum);
                    goto IL_15D;
                }
                if (a == "australia")
                {
                    this.country = AbstractScraper.Country.Australia;
                    text3        = string.Format("http://local.yahoo.com.au/search/{0}/{1}?search.offset={2}", text2, text.Replace("/", "+"), (pageNum - 1) * 20);
                    goto IL_15D;
                }
                if (a == "uk")
                {
                    this.country = AbstractScraper.Country.UK;
                    text3        = string.Format("http://uk.local.yahoo.com/search.html?poi={0}&p={1}&cb={2}&output=html", text.Replace("/", "+"), text2, (pageNum - 1) * 10 + 1);
                    goto IL_15D;
                }
            }
            text3        = string.Format("http://local.yahoo.com/results?csz={0}&stx={1}&pg_nm={2}", text.Replace("/", "+"), text2, pageNum);
            this.country = AbstractScraper.Country.USA;
IL_15D:
            if (base.Radius > 0f)
            {
                text3 += string.Format("&radius={0}", base.Radius.ToString("#0.##"));
            }
            return(text3);
        }
예제 #2
0
        protected override string GetUrl(SearchCategory scLocation, SearchCategory scCategory, string keyword, int pageNum)
        {
            string text  = scLocation.Url.Replace(" ", "+");
            string text2 = scCategory.Url.Replace(" ", "+");
            string text3 = string.Empty;

            keyword = UrlDownloader.UrlEncode(keyword);
            string text4 = scLocation.Meta ?? string.Empty;
            string a;

            if ((a = text4) != null)
            {
                if (a == "canada")
                {
                    this.country = AbstractScraper.Country.Canada;
                    text2        = UrlDownloader.SkipHtmlTags(text2.Replace('-', ' '));
                    text3        = (string.IsNullOrEmpty(keyword) ? string.Format("http://www.yellowpages.ca/search/?stype=si&what={0}&where={1}", text2, text) : string.Format("http://www.yellowpages.ca/search/?stype=si&what={0}+{1}&where={2}", text2, keyword, text));
                    goto IL_1D9;
                }
                if (a == "australia")
                {
                    if (base.Downloader != null)
                    {
                        base.Downloader.KeepAlive = false;
                    }
                    this.country = AbstractScraper.Country.Australia;
                    text3        = (string.IsNullOrEmpty(keyword) ? string.Format("http://www.yellowpages.com.au/search/listings?clue={1}&locationClue={0}&x=0&y=0&pageNumber={2}", text, text2, pageNum) : string.Format("http://www.yellowpages.com.au/search/listings?clue={1}+{3}&locationClue={0}&x=0&y=0&pageNumber={2}", new object[]
                    {
                        text,
                        text2,
                        pageNum,
                        keyword
                    }));
                    goto IL_1D9;
                }
                if (a == "uk")
                {
                    this.country = AbstractScraper.Country.UK;
                    text3        = (string.IsNullOrEmpty(keyword) ? string.Format("http://www.yell.com/ucs/UcsSearchAction.do?keywords={0}&location={1}&pageNum={2}", text2, text, pageNum) : string.Format("http://www.yell.com/ucs/UcsSearchAction.do?keywords={0}+{1}&location={2}&pageNum={3}", new object[]
                    {
                        text2,
                        keyword,
                        text,
                        pageNum
                    }));
                    goto IL_1D9;
                }
            }
            text3 = (string.IsNullOrEmpty(keyword) ? string.Format("http://www.yellowpages.com/{0}/{1}?page={2}", text, text2, pageNum) : string.Format("http://www.yellowpages.com/{0}/{1}?q={2}&page={3}", new object[]
            {
                text,
                text2,
                keyword,
                pageNum
            }));
            this.country = AbstractScraper.Country.USA;
IL_1D9:
            if (base.Radius > 0f)
            {
                text3 += string.Format("&refinements[radius]={0}", base.Radius.ToString("#0.##"));
            }
            return(text3);
        }
예제 #3
0
        public virtual void Search()
        {
            if (this.Callback != null)
            {
                this.Callback.Init(this.Locations.Count * this.Categories.Count);
            }
            this.terminated = false;
            string text = UrlDownloader.UrlEncode(this.Keyword);

            if (this.Categories.Count <= 0)
            {
                if (!this.allowsCategorylessSearch)
                {
                    if (this.downloader != null && this.downloader.errorCallback != null)
                    {
                        this.downloader.errorCallback.Log("No categories selected.");
                    }
                    return;
                }
                if (string.IsNullOrEmpty(text))
                {
                    if (this.downloader != null && this.downloader.errorCallback != null)
                    {
                        this.downloader.errorCallback.Log("No keyword and categories selected.");
                    }
                    return;
                }
            }
            if (this.Locations.Count <= 0)
            {
                if (this.downloader != null && this.downloader.errorCallback != null)
                {
                    this.downloader.errorCallback.Log("No locations selected.");
                }
                return;
            }
            AbstractScraper.PageProcessDelegate    pageProcessDelegate = string.IsNullOrEmpty(text) ? new AbstractScraper.PageProcessDelegate(this.ProcessSimpleRequest) : new AbstractScraper.PageProcessDelegate(this.ProcessKeywordRequest);
            Queue <KeyValuePair <Thread, object> > queue = new Queue <KeyValuePair <Thread, object> >();

            if (this.Categories.Count > 0)
            {
                using (List <SearchCategory> .Enumerator enumerator = this.Locations.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        SearchCategory current = enumerator.Current;
                        foreach (SearchCategory current2 in this.Categories)
                        {
                            object[] value = new object[]
                            {
                                this.campaign.Leads,
                                current,
                                current2,
                                text,
                                pageProcessDelegate
                            };
                            queue.Enqueue(new KeyValuePair <Thread, object>(new Thread(new ParameterizedThreadStart(this.ProcessSearch))
                            {
                                Name = string.Format("{0}|{1}", current.Name, current2.Name)
                            }, value));
                        }
                    }
                    goto IL_2C0;
                }
            }
            foreach (SearchCategory current3 in this.Locations)
            {
                SearchCategory searchCategory = new SearchCategory();
                searchCategory.Name = text;
                searchCategory.Url  = text;
                object[] value2 = new object[]
                {
                    this.campaign.Leads,
                    current3,
                    searchCategory,
                    null,
                    pageProcessDelegate
                };
                queue.Enqueue(new KeyValuePair <Thread, object>(new Thread(new ParameterizedThreadStart(this.ProcessSearch))
                {
                    Name = string.Format("{0}|{1}", current3.Name, searchCategory.Name)
                }, value2));
            }
IL_2C0:
            List <Thread> list = new List <Thread>(this.maxThreadCount);

            Thread.CurrentThread.Priority = ThreadPriority.Lowest;
            int i = 0;

            while (queue.Count > 0 || list.Count > 0)
            {
                if (this.terminated)
                {
                    break;
                }
                while (list.Count < this.maxThreadCount && queue.Count > 0)
                {
                    KeyValuePair <Thread, object> keyValuePair = queue.Dequeue();
                    list.Add(keyValuePair.Key);
                    keyValuePair.Key.Start(keyValuePair.Value);
                }
                if (this.terminated)
                {
                    break;
                }
                i = 0;
                while (i < list.Count)
                {
                    if (list[i].ThreadState == ThreadState.Stopped)
                    {
                        list.RemoveAt(i);
                        if (this.Callback != null)
                        {
                            this.Callback.ShowProgress();
                        }
                    }
                    else
                    {
                        i++;
                    }
                }
            }
            if (this.Callback != null)
            {
                this.Callback.Finish();
            }
            if (this.downloader != null && this.downloader.errorCallback != null)
            {
                if (this.terminated)
                {
                    this.downloader.errorCallback.Log("Search has been stopped.");
                    return;
                }
                this.downloader.errorCallback.Log("Search finished.");
            }
        }