how can I move part with while loop in other function with keeping an iterator pattern?…
- User
how can I move part with while loop in other function with keeping an iterator pattern?
public async IAsyncEnumerable NextPage(PonsseSalesScrapingBrowser scraper) { yield return StringUrl(); // for first page instance. var page = scraper.Page(); await page.ScrollBottom(); var pageNavigationElement = await page.GetElementWithClassFormatter(PageNavigationSelector); if (pageNavigationElement.HasValue == false) yield break;
var html = await pageNavigationElement.Value.GetOuterHtmlString(); if (html.HasValue == false) yield break; var htmlDocument = new HtmlDocument(); htmlDocument.LoadHtml(html.Value); while (true) { page = scraper.Page(); await page.ScrollBottom(); pageNavigationElement = await page.GetElementWithClassFormatter(PageNavigationSelector); if (pageNavigationElement.HasValue == false) yield break; html = await pageNavigationElement.Value.GetOuterHtmlString(); if (html.HasValue == false) yield break; htmlDocument = new HtmlDocument(); htmlDocument.LoadHtml(html.Value); var navigationNode = htmlDocument.DocumentNode.SelectSingleNode(PageNavigationListXpath); var pageNodes = navigationNode?.SelectNodes(".//a[@class='pageResults']"); if (pageNodes == null || pageNodes.Count == 0) yield break; var nextPageNode = pageNodes.FirstOrDefault(p => p.InnerText == "Следующая"); if (nextPageNode == null) yield break; _currentPage++; yield return StringUrl(); } }
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.