Exemplo n.º 1
0
        /// <summary>
        /// Perform a search on LeBonCoin and returns the <code>page</code>th page of results
        /// </summary>
        /// <param name="query"></param>
        /// <param name="page"></param>
        /// <returns></returns>
        public IEnumerable <SearchResult> Search(SearchQuery query, int page)
        {
            query.Page = page;

            var document = RetrieveDocumentAsync(query.Build());

            //Debug.WriteLine("Parsing the Document");
            // The main content is inside #ContainerMain
            var body = document.GetElementbyId("ContainerMain");

            // We iterate on each div to find the appropriate one
            // It _should_ be the 38th div according to HAP, but this might change
            // We need to find a div.list

            var list = body.ChildNodes.Where(node => node.Attributes.Contains("class") &&
                                             node.Attributes["class"].Value.Contains("list"))
                       .FirstOrDefault();

            if (list == null)
            {
                throw new Exception("Couldn't find any div with a .list class");
            }
            // HAP Parses text as a #text node. ChildNodes[0] is always a #text node.
            // The next one is the one we're interested in.
            //Debug.WriteLine("Parsing the list");
            list = list.ChildNodes[1].ChildNodes[1];

            return(BuildSearchList(list));
        }
Exemplo n.º 2
0
        public int GetPageCount(SearchQuery query)
        {
            var doc = RetrieveDocumentAsync(query.Build());
            var paging = doc.GetElementbyId("paging");
            var numPagesLink = paging.ChildNodes[paging.ChildNodes.Count - 2].ChildNodes[1].Attributes["href"].Value;

            var numPagesStr = Regex.Replace(numPagesLink, @"[^(o=)\d+]", "").Replace("o", "").Replace("=", "");
            var numPages = Int32.Parse(numPagesStr);

            return numPages;
        }
Exemplo n.º 3
0
        public int GetPageCount(SearchQuery query)
        {
            var doc          = RetrieveDocumentAsync(query.Build());
            var paging       = doc.GetElementbyId("paging");
            var numPagesLink = paging.ChildNodes[paging.ChildNodes.Count - 2].ChildNodes[1].Attributes["href"].Value;

            var numPagesStr = Regex.Replace(numPagesLink, @"[^(o=)\d+]", "").Replace("o", "").Replace("=", "");
            var numPages    = Int32.Parse(numPagesStr);

            return(numPages);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Perform a search on LeBonCoin and returns the <code>page</code>th page of results
        /// </summary>
        /// <param name="query"></param>
        /// <param name="page"></param>
        /// <returns></returns>
        public IEnumerable<SearchResult> Search(SearchQuery query, int page)
        {
            query.Page = page;

            var document = RetrieveDocumentAsync(query.Build());

            //Debug.WriteLine("Parsing the Document");
            // The main content is inside #ContainerMain
            var body = document.GetElementbyId("ContainerMain");

            // We iterate on each div to find the appropriate one
            // It _should_ be the 38th div according to HAP, but this might change
            // We need to find a div.list

            var list = body.ChildNodes.Where(node => node.Attributes.Contains("class") &&
                                             node.Attributes["class"].Value.Contains("list"))
                                      .FirstOrDefault();
            if (list == null)
            {
                throw new Exception("Couldn't find any div with a .list class");
            }
            // HAP Parses text as a #text node. ChildNodes[0] is always a #text node.
            // The next one is the one we're interested in.
            //Debug.WriteLine("Parsing the list");
            list = list.ChildNodes[1].ChildNodes[1];

            return BuildSearchList(list);
        }