Example #1
0
 public void TestMethod1()
 {
     _driver.Navigate().GoToUrl("http://matterspace.azurewebsites.net/Account/Register");
     _driver.FindElementByCssSelector("#Email").SendKeys("*****@*****.**");
     _driver.FindElementByCssSelector("#Password").SendKeys("1234qwerREWQ$#@!");
     _driver.FindElementByCssSelector("#ConfirmPassword").SendKeys("1234qwerREWQ$#@!");
     _driver.FindElementByCssSelector("body > form > div > div > div.card-block > div:nth-child(4) > div > button").Click();
     Assert.AreEqual(_driver.FindElementByCssSelector("body > div.container.app-container > div > div.col-4.side-bar-column > div:nth-child(1) > p").Text, "Posts you are subscribed to");
 }
Example #2
0
        public string CheckProxy()
        {
            string Ip = "";

            if (driver != null)
            {
                PhantomJSDriverService service = PhantomJSDriverService.CreateDefaultService();
                service.HideCommandPromptWindow = true;
                service.Proxy = proxyIP;

                PhantomJSDriver ghostDriver = new PhantomJSDriver(service);
                ghostDriver.Navigate().GoToUrl("http://whatismyipaddress.com/zh-cn/index");
                Ip = ghostDriver.FindElementByCssSelector("#section_left > div:nth-child(2)").Text;
            }

            return(Ip);
        }
Example #3
0
        static void AccessNasdaqEurope()
        {
            List <Target> stockList = AccessFiles.getList(StockName.NasdaqEurope);

            using (PhantomJSDriver driver = new PhantomJSDriver(@"C:\phantomjs-2.1.1-windows\bin"))
            {
                foreach (Target stock in stockList)
                {
                    driver.Url = stock.urlIdentifier;
                    driver.Navigate();
                    var      table       = driver.FindElementByCssSelector("table");
                    string[] valueChange = driver.FindElementByClassName("valueChange").Text.Split('(');
                    //In case of no change, the website has an empty string rather than 0, which we fix in the line below
                    if (valueChange[0].Trim() == String.Empty)
                    {
                        valueChange[0] = "0";
                    }

                    Instrument myInstrument = new Instrument();
                    {
                        myInstrument.PctChange(valueChange[1].Replace("%", string.Empty).Replace(")", string.Empty));
                        myInstrument.Change(valueChange[0]);
                        myInstrument.LastPrice(driver.FindElementByClassName("valueLatest").Text);
                        myInstrument.DayHigh(table.FindElement(By.ClassName("hp")).Text);
                        myInstrument.DayLow(table.FindElement(By.ClassName("lp")).Text);
                        myInstrument.Volume(table.FindElement(By.ClassName("tv")).Text);
                        myInstrument.PrevClose(table.FindElement(By.ClassName("op")).Text);
                        //    myInstrument.Bid(innerText[7]);
                        //    myInstrument.Ask(innerText[23]);
                        myInstrument.ticker            = stock.shortIdentifier;
                        myInstrument.timestamp         = System.DateTime.Now;
                        myInstrument.stockExchangeName = StockName.NasdaqEurope;
                        myInstrument.url = stock.urlIdentifier;
                    }
                    InstrumentContext ctx = new InstrumentContext();
                    ctx.Instruments.InsertOne(myInstrument);
                }
            }
        }
        private bool findCases(string path, CrossRefNumber crossRef)
        {
            try
            {
                takescreenshot("before finding cases");
                var resFoundSel = "#SmartSearchResults";
                var resFound    = FindElementIfExists(By.CssSelector(resFoundSel));
                if (resFound == null)
                {
                    logCaseNotFound(crossRef);
                    return(true);
                }
                string tbodysel = "#CasesGrid > table:nth-child(1) > tbody:nth-child(3)";
                var    tbody    = driver.FindElementByCssSelector(tbodysel);
                var    trs      = tbody.FindElements(By.TagName("tr"));
                Console.WriteLine(trs.Count);
                string allcasesUrl = driver.Url;
                foreach (var tr1 in trs)
                {
                    CourtCase case1    = new CourtCase();
                    var       caseLink = tr1.FindElement(By.CssSelector(".caseLink"));
                    case1.URL     = caseLink.GetAttribute("data-url");
                    case1.caseNum = crossRef.refNum;
                    case_ref_num.cases.Add(case1);
                    new Actions(driver).Click(caseLink).Perform();
                    Thread.Sleep(1000);
                    string case_info_div_sel = "#divCaseInformation_body";
                    try
                    {
                        var body = new WebDriverWait(driver, TimeSpan.FromSeconds(submit_wait)).Until(ExpectedConditions.ElementExists(By.CssSelector(case_info_div_sel)));
                    }
                    catch (Exception ex)
                    {
                        Thread.Sleep(1000);
                        try
                        {
                            var body = new WebDriverWait(driver, TimeSpan.FromSeconds(submit_wait)).Until(ExpectedConditions.ElementExists(By.CssSelector(case_info_div_sel)));
                        }
                        catch (Exception ex1)
                        {
                            Console.WriteLine(driver.Url);
                            Console.WriteLine(ex1.Message);
                            return(false);
                        }
                    }

                    Console.WriteLine("case found" + caseLink.Text);
                    Thread.Sleep(1000);
                    bool flg = process_case(path, case1);
                    if (!flg)
                    {
                        return(flg);
                    }
                }
                return(true);
            }
            catch (Exception ex)
            {
                takescreenshot("exception findcases");
                Console.WriteLine(driver.Url);
                return(false);
            }
        }
Example #5
0
        public AccountStatement GetAccountStatement(DateTime From, DateTime To)
        {
            if (driver != null)
            {
                try {
                    driver.SwitchTo().Window(driver.CurrentWindowHandle);
                    driver.SwitchTo().Frame("frame_menu");
                    driver.FindElementById("RRAAClink").Click();

                    driver.SwitchTo().Window(driver.CurrentWindowHandle);
                    driver.SwitchTo().Frame("frame_txn");

                    SelectElement elem = new SelectElement(driver.FindElementByName("fldacctno"));
                    elem.SelectByValue(this.Account_Value);

                    //driver.SwitchTo().Window(driver.CurrentWindowHandle);
                    //driver.SwitchTo().Frame("frame_txn");
                    var abcd = driver.FindElementsByClassName("objselect");

                    SelectElement elem2 = new SelectElement(abcd[1]);
                    elem2.SelectByValue("3");

                    driver.FindElementById("fldfromdateid").SendKeys(From.ToString("dd-MM-yyyy"));
                    driver.FindElementById("fldtodateid").SendKeys(To.ToString("dd-MM-yyyy"));

                    driver.FindElementByName("fldsubmit").Click();

                    var      alltables = driver.FindElementsByClassName("graphtable");
                    string   abc       = alltables[0].GetAttribute("innerHTML");
                    Document body      = Supremes.Dcsoup.Parse(abc);

                    AccountStatement statement = new AccountStatement();
                    statement.OpeningBalance = HelpingClass.ToDouble(body.Body.TextNodes[4].Text);
                    statement.ClosingBalance = HelpingClass.ToDouble(body.Body.TextNodes[5].Text);

                    abc  = alltables[1].GetAttribute("innerHTML");
                    body = Supremes.Dcsoup.ParseBodyFragment("<table>" + abc + "</table>");

                    List <AccountActivity> activities = new List <AccountActivity>();
                    AccountActivity        activity   = new AccountActivity();

                    Elements trs = body.Select("tr");
                    Elements tds = null;

                    bool isavilable = false;

                    abc  = driver.FindElementByClassName("standardtable").GetAttribute("innerHTML");
                    body = Supremes.Dcsoup.ParseBodyFragment("<table>" + abc + "</table>");
                    string[] arr         = body.Body.Text.Split(new string[] { "Pages : (" }, StringSplitOptions.None);
                    int      totalpage   = Convert.ToInt32(arr[1].Split(')')[0].Trim());
                    int      currentpage = 1;
                    do
                    {
                        for (int i = 0; i < trs.Count; i++)
                        {
                            if (i != 0)
                            {
                                tds      = trs[i].Select("td");
                                activity = new AccountActivity();

                                activity.TransactionDate        = DateTime.ParseExact(tds[0].OwnText, "dd-MM-yyyy", CultureInfo.InvariantCulture);
                                activity.ValueDate              = DateTime.ParseExact(tds[1].OwnText, "dd-MM-yyyy", CultureInfo.InvariantCulture);
                                activity.TransactionReferenceNo = tds[2].OwnText;
                                activity.Description            = tds[3].OwnText;
                                activity.Debit   = HelpingClass.ToDouble(tds[4].OwnText);
                                activity.Credit  = HelpingClass.ToDouble(tds[5].OwnText);
                                activity.Balance = HelpingClass.ToDouble(tds[6].OwnText);

                                activities.Add(activity);
                            }
                        }

                        if (currentpage < totalpage)
                        {
                            currentpage++;
                            driver.FindElementByCssSelector("a[href=\"javascript:SendPageRequest(" + currentpage.ToString() + ")\"]").Click();

                            alltables = driver.FindElementsByClassName("graphtable");
                            abc       = alltables[1].GetAttribute("innerHTML");
                            body      = Supremes.Dcsoup.ParseBodyFragment("<table>" + abc + "</table>");

                            trs        = body.Select("tr");
                            isavilable = true;
                        }
                        else
                        {
                            isavilable = false;
                        }
                    } while (isavilable);

                    statement.Activities = activities.AsReadOnly();

                    return(statement);
                }

                catch
                {
                    throw new Exception("(ErrorCode:11) Network Or Service is not available Or May be Problem occured While Fetching Account Details Try Again..");
                }
            }

            else
            {
                throw new Exception("(ErrorCode:10) Account Detail object not initialized");
            }
        }
        /// <summary>
        /// 解析出需要下载的资源数并添加到数据库
        /// </summary>
        /// <param name="htmlFilePath">已经解析的html文件</param>
        public void ExtraDownloadSource(string html, Guid taskId)
        {
            //解析出资源
            var regExt = new Regex("\\<a\\s*href\\=\"(?<href>\\/p\\/\\S+\\/)\"\\>");
            var matchs = regExt.Matches(html);

            var task = mediaService.GetMediatask(taskId);

            if (matchs != null && matchs.Count > 0)
            {
                for (int i = 0; i < matchs.Count; i++)
                {
                    //明细页面路径
                    var url = baseHttpUrl + matchs[i].Groups["href"].Value;
                    using (var driver = new PhantomJSDriver(PhantomJSDriverService.CreateDefaultService()))
                    {
                        //解析文件
                        $"正在浏览资源:{url}".Log(true);
                        driver.Navigate().GoToUrl(url);
                        var htmlDetail = driver.PageSource;
                        IList <IWebElement> mediaUrls = new List <IWebElement>();
                        try
                        {
                            var img = driver.FindElementByCssSelector("._2di5p");
                            if (img != null)
                            {
                                mediaUrls.Add(img);
                                "找到资源所在的唯一标签".Log(true);
                            }
                        }
                        catch
                        {
                            mediaUrls = driver.FindElements(By.TagName("img"));
                            "找到资源的img标签".Log(true);
                        }
                        driver.Quit();
                        foreach (var item in mediaUrls)
                        {
                            var mediaUrl = item.GetAttribute("src");
                            $"上传下载任务:{mediaUrl}".Log(true);
                            mediaService.AddDownload(new DownloadEntity
                            {
                                DownloadId     = Guid.NewGuid(),
                                SortValue      = DateTime.Now.ToString("yyyyMMddHHmmssfff"),
                                Disabled       = 0,
                                Rec_CreateBy   = Guid.Empty,
                                Rec_CreateTime = DateTime.Now,
                                Rec_ModifyBy   = Guid.Empty,
                                Rec_ModifyTime = DateTime.Now,
                                HttpUrl        = mediaUrl,
                                DirName        = task.Url.Substring(task.Url.LastIndexOf('/') + 1)
                            });
                        }
                    }
                }
                "该用户全部任务收集完毕!".Log(true);
                task.Disabled = 1;
                mediaService.UpdateMediatask(task);
                "更新用户资源解析任务的状态为已解析...".Log(true);
            }
        }
Example #7
0
        public static bool ParseProperty(string link)
        {
            PhantomJSDriver driver = CreateDriver();

            try
            {
                if (driver.SessionId == null)
                {
                    driver = CreateDriver();
                }

                //переход по стартовой ссылке города
                while (true)
                {
                    try
                    {
                        driver.Navigate().GoToUrl(link);
                        break;
                    }
                    catch (Exception ex)
                    {
                        logger.Trace(ex, "Ошибка получения страницы, время ожидания истекло. {0},{1}", ex.Message, ex.StackTrace);
                        logger.Error(ex, "Ошибка получения страницы, время ожидания истекло. {0},{1}", ex.Message, ex.StackTrace);
                        driver.Quit();
                        driver = CreateDriver();
                    }
                }

                if (!link.Contains("sold"))
                {
                    Console.WriteLine("Property isn't sold." + link);
                    logger.Info("Property isn't sold. {0}", link);
                    return(false);
                }

                Dictionary <string, object> mainProperties = driver.ExecuteScript("return trulia.pdp.propertyJSON") as Dictionary <string, object>;
                HomeProperty hp = new HomeProperty();
                try { hp.addressForDisplay = (string)mainProperties[Constants.HomePropertyJSObjectKeys.addressForDisplay]; } catch { }
                try { hp.addressForLeadForm = (string)mainProperties[Constants.HomePropertyJSObjectKeys.addressForLeadForm]; } catch { }
                try { hp.agentName = (string)mainProperties[Constants.HomePropertyJSObjectKeys.agentName]; } catch { }
                try { hp.apartmentNumber = (string)mainProperties[Constants.HomePropertyJSObjectKeys.apartmentNumber]; } catch { }
                try { hp.builderCommunityId = (string)mainProperties[Constants.HomePropertyJSObjectKeys.builderCommunityId]; } catch { }
                try { hp.builderName = (string)mainProperties[Constants.HomePropertyJSObjectKeys.builderName]; } catch { }
                try { hp.city = (string)mainProperties[Constants.HomePropertyJSObjectKeys.city]; } catch { }
                try { hp.communityFloors = null; } catch { }//!!!
                try { hp.communityOtherFeatures = null; } catch { }   //!!!
                try { hp.county = (string)mainProperties[Constants.HomePropertyJSObjectKeys.county]; } catch { }
                try { hp.countyFIPS = (string)mainProperties[Constants.HomePropertyJSObjectKeys.countyFIPS]; } catch { }
                try { hp.dataPhotos = (string)mainProperties[Constants.HomePropertyJSObjectKeys.dataPhotos]; } catch { }
                try { hp.description = driver.FindElementByCssSelector("#corepropertydescription").Text; } catch { } //!!!!!!!!!!!!!!!!
                try { hp.directLink = link; } catch { }
                try { hp.features = driver.FindElementByCssSelector(".mtl").Text; } catch { }                        //!!!!!!!!!!
                try { hp.formattedBedAndBath = (string)mainProperties[Constants.HomePropertyJSObjectKeys.formattedBedAndBath]; } catch { }
                try { hp.formattedLotSize = (string)mainProperties[Constants.HomePropertyJSObjectKeys.formattedLotSize]; } catch { }
                try { hp.formattedPrice = (string)mainProperties[Constants.HomePropertyJSObjectKeys.formattedPrice]; } catch { }
                try { hp.formattedSqft = (string)mainProperties[Constants.HomePropertyJSObjectKeys.formattedSqft]; } catch { }
                try { hp.hasOpenHouse = (bool)mainProperties[Constants.HomePropertyJSObjectKeys.hasOpenHouse]; } catch { }
                try { hp.hasPhotos = (bool)mainProperties[Constants.HomePropertyJSObjectKeys.hasPhotos]; } catch { }
                try { hp.HomeDetails = null; } catch { } //!!!!
                try { hp.idealIncome = -1; } catch { }   //!!!!
                try { hp.indexSource = (string)mainProperties[Constants.HomePropertyJSObjectKeys.indexSource]; } catch { }
                try { hp.isBuilder = (bool)mainProperties[Constants.HomePropertyJSObjectKeys.isBuilder]; } catch { }
                try { hp.isBuilderCommunity = (bool)mainProperties[Constants.HomePropertyJSObjectKeys.isBuilderCommunity]; } catch { }
                try { hp.isForeclosure = (bool)mainProperties[Constants.HomePropertyJSObjectKeys.isForeclosure]; } catch { }
                try { hp.isForSale = (bool)mainProperties[Constants.HomePropertyJSObjectKeys.isForSale]; } catch { }
                try { hp.isPlan = (bool)mainProperties[Constants.HomePropertyJSObjectKeys.isPlan]; } catch { }
                try { hp.isPromotedCommunity = (bool)mainProperties[Constants.HomePropertyJSObjectKeys.isPromotedCommunity]; } catch { }
                try { hp.isRealogy = (bool)mainProperties[Constants.HomePropertyJSObjectKeys.isRealogy]; } catch { }
                try { hp.isRental = (bool)mainProperties[Constants.HomePropertyJSObjectKeys.isRental]; } catch { }
                try { hp.isRentalCommunity = (bool)mainProperties[Constants.HomePropertyJSObjectKeys.isRentalCommunity]; } catch { }
                try { hp.isSpec = (bool)mainProperties[Constants.HomePropertyJSObjectKeys.isSpec]; } catch { }
                try { hp.isSrpFeatured = (bool)mainProperties[Constants.HomePropertyJSObjectKeys.isSrpFeatured]; } catch { }
                try { hp.isStudio = (bool)mainProperties[Constants.HomePropertyJSObjectKeys.isStudio]; } catch { }
                try { hp.isSubsidized = (bool)mainProperties[Constants.HomePropertyJSObjectKeys.isSubsidized]; } catch { }
                try { hp.lastSaleDate = (string)mainProperties[Constants.HomePropertyJSObjectKeys.lastSaleDate]; } catch { }
                try { hp.latitude = (double)mainProperties[Constants.HomePropertyJSObjectKeys.latitude]; } catch { }
                try { hp.listingId = (long)mainProperties[Constants.HomePropertyJSObjectKeys.listingId]; } catch { }
                try { hp.listingType = (string)mainProperties[Constants.HomePropertyJSObjectKeys.listingType]; } catch { }
                try { hp.locationId = (string)mainProperties[Constants.HomePropertyJSObjectKeys.locationId]; } catch { }
                try { hp.longitude = (double)mainProperties[Constants.HomePropertyJSObjectKeys.longitude]; } catch { }
                try { hp.metaInfo = null; } catch { }//!!!!
                try { hp.numBathrooms = Convert.ToInt32(mainProperties[Constants.HomePropertyJSObjectKeys.numBathrooms]); } catch { }
                try { hp.numBedrooms = Convert.ToInt32(mainProperties[Constants.HomePropertyJSObjectKeys.numBedrooms]); } catch { }
                try { hp.numBeds = Convert.ToInt32(mainProperties[Constants.HomePropertyJSObjectKeys.numBeds]); } catch { }
                try { hp.numFullBathrooms = Convert.ToInt32(mainProperties[Constants.HomePropertyJSObjectKeys.numFullBathrooms]); } catch { }
                try { hp.numPartialBathrooms = Convert.ToInt32(mainProperties[Constants.HomePropertyJSObjectKeys.numPartialBathrooms]); } catch { }
                try { hp.pdpURL = (string)mainProperties[Constants.HomePropertyJSObjectKeys.pdpURL]; } catch { }
                try { hp.PetsAllowed = null; } catch { } // !!!!!!!!!!!
                try { hp.phone = null; } catch { }       //!!!!!!!
                try { hp.postId = (long)mainProperties[Constants.HomePropertyJSObjectKeys.postId]; } catch { }
                try { hp.pricePerSqft = (string)mainProperties[Constants.HomePropertyJSObjectKeys.pricePerSqft]; } catch { }
                try { hp.PublicRecords = null; } catch { }//!!!!!!
                try { hp.rentalPartnerDisplayText = (string)mainProperties[Constants.HomePropertyJSObjectKeys.rentalPartnerDisplayText]; } catch { }
                try { hp.type = (string)mainProperties[Constants.HomePropertyJSObjectKeys.type]; } catch { }
                try { hp.typeDisplay = (string)mainProperties[Constants.HomePropertyJSObjectKeys.typeDisplay]; } catch { }
                try { hp.shortDescription = (string)mainProperties[Constants.HomePropertyJSObjectKeys.shortDescription]; } catch { }
                try { hp.sqft = Convert.ToInt32(mainProperties[Constants.HomePropertyJSObjectKeys.sqft]); } catch { }
                try { hp.stateCode = (string)mainProperties[Constants.HomePropertyJSObjectKeys.stateCode]; } catch { }
                try { hp.stateName = (string)mainProperties[Constants.HomePropertyJSObjectKeys.stateName]; } catch { }
                try { hp.status = (string)mainProperties[Constants.HomePropertyJSObjectKeys.status]; } catch { }
                try { hp.street = (string)mainProperties[Constants.HomePropertyJSObjectKeys.street]; } catch { }
                try { hp.streetNumber = (string)mainProperties[Constants.HomePropertyJSObjectKeys.streetNumber]; } catch { }
                try { hp.yearBuilt = Convert.ToInt32(mainProperties[Constants.HomePropertyJSObjectKeys.yearBuilt]); } catch { }
                try { hp.zipCode = (string)mainProperties[Constants.HomePropertyJSObjectKeys.zipCode]; } catch { }
                try { hp.ComparablesJSON = (string)driver.ExecuteScript("return JSON.stringify(trulia.pdp.comparableProperties)"); } catch { }
                long ID = hp.InsertToDb();
                if (ID > 0)
                {
                    List <PropertyCrime> crimes = GetCrimes(driver, ID);
                    crimes.ForEach(crime => crime.InsertToDb());
                }
                if (ID > 0)
                {
                    List <PropertySchool> schools = GetSchools(driver, ID);
                    schools.ForEach(school => school.InsertToDb());
                }
                return(true); //все прошло успешно
            }
            catch (OpenQA.Selenium.WebDriverException ex)
            {
                logger.Error(ex, "Возникло исключение web-драйвера: {1}, {0}", ex.StackTrace, ex.Message);
                return(false);
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Возникло неизвестное исключение: {1}, {0}", ex.StackTrace, ex.Message);
                return(false);
            }
            finally
            {
                driver.Quit();
            }
        }