Пример #1
0
        static void Main(string[] args)
        {
            //ProcessCareerCupQuestions();
            var outFile   = "programcreek.json";
            var questions = new List <Question>();
            var driver    = PhantomJSExt.InitPhantomJS();
            var site      = "http://www.programcreek.com/2012/11/top-10-algorithms-for-coding-interview/";

            try
            {
                GetQuestions(questions, driver, site);
                foreach (var q in questions)
                {
                    driver.Navigate().GoToUrl(q.Url);
                    var section = driver.FindElement(By.ClassName("entrybody"));
                    var p       = section.FindElement(By.XPath("./p"));
                    var qText   = p.Text;
                    q.Text = qText;
                }
            }
            finally
            {
                driver.Quit();
                InterviewData data = new InterviewData();
                data.Questions = questions;
                var json = JsonConvert.SerializeObject(data);
                FileIO.Write(outFile, json);
            }
        }
Пример #2
0
        private static IWebDriver GetWebDriver()
        {
            switch (browserType)
            {
            case BrowserType.Phantom:
                return(PhantomJSExt.InitPhantomJS());

            case BrowserType.Chrome:
                return(new ChromeDriver());

            default:
                throw new InvalidOperationException(string.Format("Error: Unhandled browser type {0}"));
            }
        }
Пример #3
0
        private static void ProcessCareerCupQuestions()
        {
            var dir       = @"C:\Users\ralph.joachim\Documents\Visual Studio 2015\Projects\CareerCupToolkit\CareerCupToolkit";
            var questions = new List <Question>();
            var driver    = PhantomJSExt.InitPhantomJS();

            try
            {
                foreach (var fName in Directory.EnumerateFiles(dir, "*.txt"))
                {
                    var fileName = Path.GetFileName(fName);
                    var index    = fileName.IndexOf('_');
                    var company  = fileName.Substring(0, index);

                    Question      q           = null;
                    var           urlFound    = true;
                    bool          lookForBody = false;
                    StringBuilder textSB      = new StringBuilder();
                    foreach (var line in FileIO.ReadFrom(fName))
                    {
                        if (line.StartsWith("-----"))
                        {
                            if (urlFound)
                            {
                                urlFound = false; lookForBody = true;
                            }
                            else if (lookForBody)
                            {
                                lookForBody = false; q.Text = textSB.ToString(); questions.Add(q); textSB = new StringBuilder();
                            }
                            continue;
                        }
                        if (line.StartsWith("Question"))
                        {
                            q         = new Question();
                            q.Company = company;
                            var i   = line.IndexOf(':');
                            var url = line.Substring(i + 1).Trim();
                            q.Url    = url;
                            urlFound = true;

                            //tag, concept, topic
                            //You will have to visit the url to get the tags to populate topic

                            driver.Navigate().GoToUrl(url);
                            List <string> tags = GetTags(driver);
                            q.Tags = tags;
                        }
                        else if (lookForBody)
                        {
                            textSB.AppendLine(line);
                        }
                    }
                }
            }
            finally
            {
                driver.Quit();
                InterviewData data = new InterviewData();
                data.Questions = questions;
                var json = JsonConvert.SerializeObject(data);
                FileIO.Write("questions.json", json);
            }
        }
Пример #4
0
        private List <Place> FindPlaces()
        {
            var count  = 0;
            var result = new List <Place>();

            foreach (var url in ReadFile("search.txt"))
            {
                //Selenium: Navigate to url
                IWebDriver driver = PhantomJSExt.InitPhantomJS();
                try
                {
                    Logger.Debug("Loading url '{0}'...", url);
                    driver.Navigate().GoToUrl(url);

                    string name, address, hours;
                    Logger.Debug("Looking for Name.....");
                    var nameElem = driver.FindElement(By.CssSelector("data-dtype=d3bn"));
                    Logger.Debug(name = nameElem.Text);
                    Logger.Debug("");

                    Logger.Debug("Looking for Address.....");
                    var addressElem = driver.FindElement(By.CssSelector("data-dtype=d3adr"));
                    var add2        = driver.FindElement(By.CssSelector(":contains('Address')"));
                    Logger.Debug(address = addressElem.Text);
                    Logger.Debug("");

                    Logger.Debug("Looking for Hours.....");
                    var hoursElem = driver.FindElement(By.CssSelector("data-dtype=d3adr"));
                    var h2        = driver.FindElement(By.CssSelector(":contains('Hours')"));
                    Logger.Debug(hours = hoursElem.Text);
                    Logger.Debug("");

                    var loc = new Place(++count, name, address, Convert(hours), null);
                    loc.GeoLocation = GetLatLong(address);

                    result.Add(loc);



                    /*
                     *                  Logger.Debug("Searching for topics...");
                     *                  IWebElement questionsLink = driver.FindElement(By.LinkText("Questions"));
                     *                  questionsLink.Click();
                     *
                     *                  var topicsCombo = driver.FindElement(By.Id("topic"));
                     *                  var options = topicsCombo.FindElements(By.TagName("option"));
                     *
                     *                  if (options == null || options.Count == 0)
                     *                  {
                     *                      throw new InvalidOperationException("Error: Unable to find list of topics!");
                     *                  }
                     *
                     *                  Logger.Debug("Successfully Retrieved topics");
                     *                  Console.WriteLine();
                     *                  foreach (var o in options)
                     *                  {
                     *                      careerCupTopics.Add(o.Text);
                     *                  }
                     */
                }
                finally
                {
                    driver.Quit();
                }

                throw new NotImplementedException();
            }
            return(result);
        }