Beispiel #1
0
        static void GetLunchPost(Restaurant restaurant)
        {
            var repository = new MongoRepositoryBase <LunchDeal>("mongodb://localhost/LunchBox", "LunchDeals");

//            IWebDriver browser = new ChromeDriver("C:\\chromeDriver\\");
            try
            {
                //Firefox's proxy driver executable is in a folder already
                //  on the host system's PATH environment variable.
                var link = restaurant.link.Split(new[] { ".com" }, StringSplitOptions.None)[1];
                link = "https://m.facebook.com" + link + "posts/";
                browser.Navigate().GoToUrl(link);

                var posts = browser.FindElements(By.CssSelector("#pages_msite_body_contents .story_body_container"));

                foreach (var post in posts)
                {
                    try
                    {
                        var moreButton = post.FindElement(By.LinkText("More"));
                        moreButton.Click();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }

                    IWebElement time = null;
                    IWebElement withoutMoreButton = null;
                    IWebElement imagelocation     = null;
                    IWebElement image             = null;

                    try
                    {
                        time = post.FindElement(By.CssSelector("[data-sigil=\"m-feed-voice-subtitle\"] abbr"));
                        withoutMoreButton = post.FindElement(By.CssSelector("[data-ad-preview=\"message\"] span"));
                        imagelocation     = post.FindElement(By.CssSelector("i.img"));
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);
                    }

                    ReadOnlyCollection <IWebElement> withMoreButtonVisible   = null;
                    ReadOnlyCollection <IWebElement> withMoreButtonInvisible = null;
                    ReadOnlyCollection <IWebElement> dealImage = null;
                    try
                    {
                        withMoreButtonVisible = post.FindElements(By.CssSelector(
                                                                      "#pages_msite_body_contents .story_body_container [data-ad-preview=\"message\"] span[data-sigil=\"expose\"] > p"));
//                        withMoreButtonInvisible = post.FindElements(By.CssSelector(
//                            "#pages_msite_body_contents .story_body_container [data-ad-preview=\"message\"] span[data-sigil=\"expose\"] div.text_exposed_show p"));

                        dealImage = post.FindElements(By.CssSelector(".userContentWrapper .uiScaledImageContainer img"));
                    }
                    catch (Exception ex)
                    {
                    }



                    try
                    {
                        if (Regex.IsMatch(time.Text, @"^\d+"))
                        {
                            if (withoutMoreButton.Text.ToLower().Contains("pietus") ||
                                withoutMoreButton.Text.ToLower().Contains("pietūs") ||
                                withoutMoreButton.Text.ToLower().Contains("pietū") ||
                                withoutMoreButton.Text.ToLower().Contains("dienos") ||
                                withoutMoreButton.Text.ToLower().Contains("pietu") ||
                                withoutMoreButton.Text.ToLower().Contains("pietums") ||
                                withoutMoreButton.Text.ToLower().Contains("sriuba"))
                            {
                                string text = withoutMoreButton.Text;

                                if (withMoreButtonVisible != null)
                                {
                                    foreach (var p in withMoreButtonVisible)
                                    {
                                        text = text + p.Text + Environment.NewLine;
                                    }
                                }

                                var deal = new LunchDeal();
                                deal.Description = text;

                                deal.RestaurantId = restaurant.id;
                                deal.id           = restaurant.id;
                                deal.time         = time.Text;
                                deal.Restaurant   = restaurant;

                                try
                                {
                                    post.Click();
                                    image         = browser.FindElement(By.CssSelector("div[data-full-size-href]"));
                                    deal.ImageUrl = image.GetAttribute("data-full-size-href");
                                }
                                catch (Exception e)
                                {
                                    Console.WriteLine(e);
                                }

                                try
                                {
                                    repository.UpdateOne(deal);
                                }
                                catch (Exception ex)
                                {
                                    Console.WriteLine(ex.Message);
                                    repository.Insert(deal);
                                }
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);
                    }
                }
            }
            catch (Exception ex)
            {
            }

            //            browser.Close();
            //            browser.Dispose();

            Console.WriteLine("Done " + restaurant.name);
//            browser.Close();
//            browser.Dispose();
        }
Beispiel #2
0
        static void Search(string query)
        {
            try
            {
                var tokken =
                    "EAAFsGfQAdhoBAIf8OpfB1RTFFvORIXHEQxqp16Oo9BciBiN5iXnwQqauDZCg2cZBUSpc2dXZCiBTfVnoKlynI4QgCHrHvlk46rWhDtk8pk2VZBFn5JhmQ9iPvoCXa4F91ZAWXVFZCG8ReZCZAbYZAD9vsjiMCVaobGZB9l1JldQZCz7CA2XyvgZAK3CJSIBFgjmX3FqGhCFZABr4TkgZDZD";

                var repository = new MongoRepositoryBase <Restaurant>("mongodb://localhost/LunchBox", "RestaurantsRaw");
                var path       =
                    "https://graph.facebook.com/v3.1/search?fields=about,app_links,checkins,cover,description,engagement,hours,id,is_permanently_closed,is_verified,link,location,name,overall_star_rating,parking,payment_options,phone,price_range,rating_count,single_line_address,website,picture{height,url,width},photos&q=" +
                    query + "&type=place&limit=999999&access_token=" + tokken;
                bool searchNext = true;
                while (searchNext)
                {
                    var result = GetProductAsync(path).Result;


                    foreach (var restaurant in result.data)
                    {
                        try
                        {
                            try
                            {
                                repository.UpdateOne(restaurant);
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine(ex.Message);
                                restaurant.location.PointLocation = new GeoJsonPoint <GeoJson2DGeographicCoordinates>(
                                    new GeoJson2DGeographicCoordinates(restaurant.location.longitude,
                                                                       restaurant.location.latitude));
                                repository.Insert(restaurant);
                            }


                            Console.WriteLine("INSERTED: " + restaurant.name);
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("FAILED!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!: " + restaurant.name);
                            Console.WriteLine(ex.Message);
                        }
                    }

                    try
                    {
                        path = result.paging.next;
                        Console.WriteLine("Search added for " + path);

                        if (result.paging.next.Length > 0)
                        {
                        }
                        else
                        {
                            searchNext = false;
                        }
                    }
                    catch (Exception e)
                    {
                        searchNext = false;
                    }
                }

                Console.WriteLine("Done ");
            }
            catch (Exception ex)
            {
            }
        }