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; }
/// <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); }
/// <summary> /// Perform a search on LeBonCoin and returns the first page of results /// </summary> /// <param name="query">The query parameters</param> /// <returns>A list of search results</returns> public IEnumerable<SearchResult> Search(SearchQuery query) { return Search(query, 1); }
private void onSearchClicked(object sender, RoutedEventArgs e) { if (searchBox.Text != "") { adList.Items.Clear(); searchResults.Clear(); posts.Clear(); LBCParser.SearchQuery query = new LBCParser.SearchQuery(searchBox.Text) { Category = SearchQuery.Categories[categorySelector.Text], Region = SearchQuery.Regions[regionSelector.Text], InTitle = (bool)inTitleOpt.IsChecked }; foreach (var res in parser.Search(query)) { var status = (Label)(statusBar.Items[0]); status.Content = "Downloading " + res.Link; adList.Items.Add(new SearchResultControl(res.Title, res.PreviewImage != null ? GetBitmapFromURI(res.PreviewImage).ToBitmapImage() : (BitmapImage)Resources["NoImage"], res.Category, res.Price)); searchResults.Add(res); } } }