예제 #1
0
        public static async Task CrawlFoodPantrySateSiteAsync(ChromeDriver driver, FoodPantryState state)
        {
            IList <FoodPantryCity> cityList = new List <FoodPantryCity>();

            driver.Navigate().GoToUrl(state.Url);

            IWebElement         tableElement = driver.FindElement(By.TagName("table"));
            IList <IWebElement> tableRow     = tableElement.FindElements(By.TagName("tr"));
            IList <IWebElement> rowTD;

            foreach (IWebElement row in tableRow)
            {
                rowTD = row.FindElements(By.XPath("//td/a"));
                foreach (IWebElement td in rowTD)
                {
                    FoodPantryCity city = new FoodPantryCity();
                    city.Name  = td.Text;
                    city.Url   = td.GetAttribute("href");
                    city.State = state;
                    cityList.Add(city);
                }
            }
            state.Cities = cityList;
            driver.Navigate().Back();
        }
예제 #2
0
        public static async Task <IList <FoodPantryState> > CrawlFoodPantryWebSiteAsync(ChromeDriver driver, ILogger log)
        {
            //Create FoodPantry Container
            FoodPantryContainer = await Common.CosmosDBUtils.CreateCosmosContainerAsync(FoodPantryContainerId, log);

            if (FoodPantryContainer != null)
            {
                log.LogInformation("Successfully created FoodPantryContainer");
            }

            IList <FoodPantryState> stateList = new List <FoodPantryState>();

            driver.Navigate().GoToUrl(FoodPantrySiteURL);

            IWebElement         tableElement = driver.FindElement(By.TagName("table"));
            IList <IWebElement> tableRow     = tableElement.FindElements(By.TagName("tr"));
            IList <IWebElement> rowTD;

            foreach (IWebElement row in tableRow)
            {
                rowTD = row.FindElements(By.XPath("//td/a"));
                foreach (IWebElement td in rowTD)
                {
                    FoodPantryState state = new FoodPantryState();
                    state.Name = td.Text;
                    state.Url  = td.GetAttribute("href");
                    stateList.Add(state);
                }
            }
            return(stateList);
        }