public void InnerTextIsNotTruncated()
 {
     using (var chrome = new Chrome(MainURI))
     {
         Assert.That(chrome.Text, Text.DoesNotContain("... (length:"), "Body inner text was truncated, a known issue which requires a work around.");
     }
 }
 public void NewChromeWithoutUrlShouldStartAtAboutBlank()
 {
     using (var chrome = new Chrome())
     {
         Assert.AreEqual("about:blank", chrome.Url);
     }
 }
Exemplo n.º 3
0
 public void AddProtocolToUrlIfOmmitted()
 {
     using (var chrome = new Chrome("www.google.com"))
     {
         Assert.That(chrome.Url, Text.StartsWith("http://"));
     }
 }
Exemplo n.º 4
0
 public void CanTypeTextIntoATextField()
 {
     using (Chrome chrome = new Chrome(MainURI))
     {
         chrome.TextField("name").TypeText("Hello world");
         Assert.That(chrome.TextField("name").Text, Is.EqualTo("Hello world"));
     }
 }
Exemplo n.º 5
0
 public void CheckFireFoxIsInheritingProperTypes()
 {
     using (var chrome = new Chrome())
     {
         Assert.IsInstanceOfType(typeof(Chrome), chrome, "Should be a Chrome instance");
         Assert.IsInstanceOfType(typeof(Browser), chrome, "Should be a Browser instance");
         Assert.IsInstanceOfType(typeof(DomContainer), chrome, "Should be a DomContainer instance");
     }
 }
        public void GoogleSearchWithEncodedQueryStringInConstructor()
        {
            var url = string.Format("http://www.google.com/search?q={0}", HttpUtility.UrlEncode("a+b"));

            using (var chrome = new Chrome(url))
            {
                Assert.That(chrome.TextField(Find.ByName("q")).Value, Is.EqualTo("a+b"));
            }
        }
        public Browser GetBrowser(Uri uri)
        {
            if (this.chrome == null)
            {
                this.chrome = (Chrome)CreateBrowser(uri);
            }

            return this.chrome;
        }
        public void CloseBrowser()
        {
            if (this.chrome == null)
            {
                return;
            }

            this.chrome.Dispose();
            this.chrome = null;
        }
Exemplo n.º 9
0
 /// <summary>
 /// Attach process as a browser.
 /// </summary>
 /// <param name="process"> The process of the browser to attach to. </param>
 /// <returns> The browser if successfully attached or otherwise null. </returns>
 public static Browser AttachToBrowser(Process process)
 {
     return(Chrome.Attach(process) ?? Edge.Attach(process) ?? InternetExplorer.Attach(process) ?? Firefox.Attach(process));
 }
        public void Execute(Dictionary <string, string> arguments)
        {
            Console.WriteLine("\r\n[*] Action: Chrome Cookies Triage\r\n");
            arguments.Remove("cookies");

            string displayFormat  = "csv";  // "csv", "table", or "json" display
            string server         = "";     // used for remote server specification
            bool   showAll        = false;  // whether to display entries with null passwords
            bool   unprotect      = false;  // whether to force CryptUnprotectData()
            bool   setneverexpire = false;  // set cookie output expiration dates to now + 100 years
            string cookieRegex    = "";     // regex to search for specific cookie names
            string urlRegex       = "";     // regex to search for specific URLs for cookies

            if (arguments.ContainsKey("/format"))
            {
                displayFormat = arguments["/format"];
            }

            if (arguments.ContainsKey("/cookie"))
            {
                cookieRegex = arguments["/cookie"];
            }

            if (arguments.ContainsKey("/url"))
            {
                urlRegex = arguments["/url"];
            }

            if (arguments.ContainsKey("/unprotect"))
            {
                unprotect = true;
            }

            if (arguments.ContainsKey("/setneverexpire"))
            {
                setneverexpire = true;
            }

            if (arguments.ContainsKey("/showall"))
            {
                showAll = true;
            }

            if (showAll)
            {
                Console.WriteLine("[*] Triaging all cookies, including expired ones.");
            }
            else
            {
                Console.WriteLine("[*] Triaging non-expired cookies. Use '/showall' to display ALL cookies.");
            }

            if (arguments.ContainsKey("/server"))
            {
                server = arguments["/server"];
                Console.WriteLine("[*] Triaging remote server: {0}\r\n", server);
            }

            // {GUID}:SHA1 keys are the only ones that don't start with /
            Dictionary <string, string> masterkeys = new Dictionary <string, string>();

            foreach (KeyValuePair <string, string> entry in arguments)
            {
                if (!entry.Key.StartsWith("/"))
                {
                    masterkeys.Add(entry.Key, entry.Value);
                }
            }
            if (arguments.ContainsKey("/pvk"))
            {
                // use a domain DPAPI backup key to triage masterkeys
                masterkeys = SharpDPAPI.Dpapi.PVKTriage(arguments);
            }
            else if (arguments.ContainsKey("/mkfile"))
            {
                masterkeys = SharpDPAPI.Helpers.ParseMasterKeyFile(arguments["/mkfile"]);
            }
            else if (arguments.ContainsKey("/password"))
            {
                string password = arguments["/password"];
                Console.WriteLine("[*] Will decrypt user masterkeys with password: {0}\r\n", password);
                if (arguments.ContainsKey("/server"))
                {
                    masterkeys = SharpDPAPI.Triage.TriageUserMasterKeys(null, true, arguments["/server"], password);
                }
                else
                {
                    masterkeys = SharpDPAPI.Triage.TriageUserMasterKeys(null, true, "", password);
                }
            }

            if (arguments.ContainsKey("/target"))
            {
                string target = arguments["/target"].Trim('"').Trim('\'');

                if (File.Exists(target))
                {
                    Console.WriteLine("[*] Target 'Cookies' File: {0}\r\n", target);
                    Chrome.ParseChromeCookies(masterkeys, target, displayFormat, showAll, unprotect, cookieRegex, urlRegex);
                }
                else
                {
                    Console.WriteLine("\r\n[X] '{0}' is not a valid file.", target);
                }
            }
            else
            {
                if (arguments.ContainsKey("/server") && !arguments.ContainsKey("/pvk") && !arguments.ContainsKey("/password"))
                {
                    Console.WriteLine("[X] The '/server:X' argument must be used with '/pvk:BASE64...' or '/password:X' !");
                }
                else
                {
                    Chrome.TriageChromeCookies(masterkeys, server, displayFormat, showAll, unprotect, cookieRegex, urlRegex, setneverexpire);
                }
            }
        }
Exemplo n.º 11
0
 public void Initialize()
 {
     chrome = new Chrome(headless: false);
 }
Exemplo n.º 12
0
        public override IList <PaymentModel> ScrapeStatement(ScraperConfigurationModel configuration, Chrome chromeDriver,
                                                             DateTime startFrom)
        {
            if (startFrom < DateTime.Now.AddYears(-2).AddDays(1))
            {
                startFrom = DateTime.Now.AddYears(-2).AddDays(1);
            }

            var driver = chromeDriver.Driver;

            Login(configuration, chromeDriver);

            var existingLinks = driver.FindElements(By.PartialLinkText("История операций")).ToList();

            var link1 = driver.FindElement(By.LinkText("Счета"));

            chromeDriver.MoveToElement(link1, 1, 1);

            WaitForPageLoad(driver);

            existingLinks = driver.FindElements(By.PartialLinkText("История операций")).Except(existingLinks).ToList();
            existingLinks.Single().Click();

            WaitForPageLoad(driver, 2);

            var selectBtn = driver.FindElement(By.Id("pt1:soc1::button"));

            var accountsChooser = driver.FindElement(By.Id("pt1:soc1::pop"));

            var accs = accountsChooser.FindElements(By.TagName("tr"));

            var result = new List <PaymentModel>();

            foreach (var acc in accs)
            {
                var tds = acc.FindElements(By.TagName("td"));
                if (tds.Count < 4)
                {
                    continue;
                }

                selectBtn.Click();

                WaitForPageLoad(driver, 2);

                tds[0].Click();

                WaitForPageLoad(driver, 2);


                var inputDate = driver.FindElement(By.Id("pt1:id1::fd"));
                inputDate.Click();

                WaitForPageLoad(driver, 2);

                chromeDriver.SendKeys(Enumerable.Repeat(Keys.Delete, 20).Join(""));
                WaitForPageLoad(driver);
                chromeDriver.SendKeys(Enumerable.Repeat(Keys.Backspace, 20).Join(""));
                WaitForPageLoad(driver);
                chromeDriver.SendKeys(Enumerable.Repeat(Keys.Delete, 20).Join(""));
                WaitForPageLoad(driver);
                chromeDriver.SendKeys(Enumerable.Repeat(Keys.Backspace, 20).Join(""));
                WaitForPageLoad(driver);
                chromeDriver.SendKeys(startFrom.ToString("ddMMyyyy"));

                var submit = driver.FindElement(By.Id("pt1:showButton::button"));
                submit.Click();

                WaitForPageLoad(driver, 2);

                var csv = driver.FindElement(By.Id("pt1:downloadCSVLink"));
                csv.Click();

                int waited = 0;
                while (chromeDriver.GetDownloads().Count < 1 && waited < 300)
                {
                    WaitForPageLoad(driver);
                    waited++;
                }

                var files = chromeDriver.GetDownloads();
                if (files.Count == 1)
                {
                    var csvFile    = files.First();
                    var csvContent = File.ReadAllLines(csvFile.FullName, Encoding.GetEncoding(1251)).Skip(1).Select(v => new AlphaStatement(v)).ToList();
                    var payments   = csvContent.Select(v => Statement(v.Date, v.AccountName, v.What, v.Income - v.Outcome, v.Kind, v.Ccy, v.Reference)).ToList();

                    var holdPayments = payments.Where(v => v.StatementReference == "HOLD").ToList();
                    payments = payments.Except(holdPayments).ToList();

                    result.AddRange(payments);
                    csvFile.Delete();
                }

                chromeDriver.CleanupDownloads();
            }


            return(result);
        }
Exemplo n.º 13
0
        internal void UpdateChromeBindings(Chrome chrome)
        {
            _chrome = chrome;
            CreateBinding(Chrome.ResizeBorderThicknessProperty.Name, _chrome, PadSizeProperty, ThicknessToDoubleConverter.Instance, Side);

            var brushBinding = new MultiBinding
            {
                Converter = new BorderBrushConverter(this),
                Mode = BindingMode.OneWay,
            };
            brushBinding.Bindings.Add(new Binding(Chrome.ActiveBorderBrushProperty.Name)
            {
                Source = _chrome,
            });
            brushBinding.Bindings.Add(new Binding(Chrome.InactiveBorderBrushProperty.Name)
            {
                Source = _chrome,
            });
            BindingOperations.SetBinding(this, BorderBrushProperty, brushBinding);
            UpdateBorderBrush();
        }
Exemplo n.º 14
0
        public async Task ProcessAsync(MessageContext context, HttpApiClient api)
        {
            //await api.SendMessageAsync(context.Endpoint, $"[DEBUG] 比较:{_other};模式:{_mode}");

            var id = await DataProvider.EnsureGetBindingIdAsync(context.UserId).ConfigureAwait(false);

            //var browser = GetBrowser();

            byte[] data = null;
            var    mode = Bleatingsheep.Osu.Mode.Standard;

            try
            {
                if (!string.IsNullOrEmpty(_mode))
                {
                    mode = Bleatingsheep.Osu.ModeExtensions.Parse(_mode);
                }
            }
            catch
            {
                await api.SendMessageAsync(context.Endpoint, "模式识别失败,fallback 到 Standard。").ConfigureAwait(false);
            }

            var url = $"http://hydrantweb/pptth/mini/{id}?height=350&mode={(int)mode}";

            if (!string.IsNullOrEmpty(_other))
            {
                var(_, user) = await OsuApi.GetUserInfoAsync(_other, mode);

                if (user == null)
                {
                    ExecutingException.Ensure(false, "对比玩家错误");
                }
                url += $"&compared={user.Id}";
            }
            using (var page = await Chrome.OpenNewPageAsync().ConfigureAwait(false))
            {
                await page.SetViewportAsync(new ViewPortOptions
                {
                    DeviceScaleFactor = 1.15,
                    Width             = 640,
                    Height            = 350,
                }).ConfigureAwait(false);

                await page.GoToAsync(url).ConfigureAwait(false);

                await Task.Delay(0).ConfigureAwait(false);

                data = await page.ScreenshotDataAsync(new ScreenshotOptions
                {
                    FullPage = true,
                    //Type = ScreenshotType.Jpeg,
                    //Quality = 100,
                }).ConfigureAwait(false);
            }

            var stopwatch    = Stopwatch.StartNew();
            var sendResponse = await api.SendMessageAsync(context.Endpoint, Message.ByteArrayImage(data)).ConfigureAwait(false);

            var elapsedTime = stopwatch.ElapsedMilliseconds;
            var failed      = sendResponse is null;

            if (failed)
            {
                await api.SendMessageAsync(context.Endpoint, "图片发送失败(确定)").ConfigureAwait(false);
            }
            (failed ? FailedElapsed : SuccessfulElapsed).Add(elapsedTime);
        }
Exemplo n.º 15
0
        public override IList <MoneyStateModel> Scrape(ScraperConfigurationModel configuration, Chrome driver)
        {
            var apiKey   = configuration.Login;
            var password = configuration.Password;

            var param = "".Replace("/", "%2F").Replace("@", "%40").Replace(";", "%3B");
            var sign  = HashHmac(password, param).ToUpper();
            var uri   = "https://api.livecoin.net/payment/balances";

            _client.DefaultRequestHeaders.Remove("Api-Key");
            _client.DefaultRequestHeaders.Add("Api-Key", apiKey);
            _client.DefaultRequestHeaders.Remove("Sign");
            _client.DefaultRequestHeaders.Add("Sign", sign);
            var response     = _client.GetAsync(uri).GetAwaiter().GetResult();
            var responseText = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();

            try
            {
                var jobj   = JArray.Parse(responseText);
                var result = new List <MoneyStateModel>();

                foreach (var item in jobj)
                {
                    var type   = item["type"].Value <string>();
                    var amount = item["value"].Value <double>();
                    var ccy    = item["currency"].Value <string>();

                    if (amount > 0 && type == "total")
                    {
                        result.Add(Money(ccy, amount, ccy));
                    }
                }

                var tickers = result.Select(v => v.Ccy).Distinct().Where(v => v != CurrencyExtensions.USD).Select(v => v + "/" + CurrencyExtensions.USD)
                              .ToList();
                uri          = "https://api.livecoin.net/exchange/ticker";
                response     = _client.GetAsync(uri).GetAwaiter().GetResult();
                responseText = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();

                jobj = JArray.Parse(responseText);

                foreach (var item in jobj)
                {
                    var symbol = item["symbol"].Value <string>();

                    if (!tickers.Contains(symbol))
                    {
                        continue;
                    }

                    var maxbid = item["max_bid"].Value <double>();
                    var minask = item["min_ask"].Value <double>();

                    var rate = (maxbid + minask) / 2;

                    result.Add(Money(symbol, rate, symbol));
                }

                return(result);
            }
            catch
            {
                Logger.LogInformation($"LiveCoin response:\n{responseText}");
                throw;
            }
        }
Exemplo n.º 16
0
        public override IList <MoneyStateModel> Scrape(ScraperConfigurationModel configuration, Chrome chrome)
        {
            DoLogin(configuration, chrome);

            var driver = chrome.Driver;

            var accounts = GetElements(driver, By.ClassName("bank_account"));

            var result = new List <MoneyStateModel>();

            foreach (var acc in accounts)
            {
                var title = acc.FindElement(By.ClassName("bank_account_name")).Text;

                var amount = acc.FindElement(By.ClassName("bank_account_money")).Text;

                amount = new string(amount.Where(v => char.IsDigit(v) || v == ',').ToArray());

                var doubleAmount = double.Parse(amount, new NumberFormatInfo()
                {
                    NumberDecimalSeparator = ","
                });

                result.Add(Money(title, doubleAmount, CurrencyExtensions.RUB));
            }

            return(result);
        }
Exemplo n.º 17
0
        public override IList <PaymentModel> ScrapeStatement(ScraperConfigurationModel configuration, Chrome chrome, DateTime startFrom)
        {
            DoLogin(configuration, chrome);

            var driver = chrome.Driver;

            var btns = GetElements(driver, By.TagName("button"));

            var rightBtn = btns.First(s => s.Text.ToLower().Contains("выписка"));

            rightBtn.Click();

            var form = GetElement(driver, By.ClassName("address_form"));

            var switches = form.FindElements(By.ClassName("switch_item"));

            var htmlSwitch = switches.First(s => s.Text == "1C");

            htmlSwitch.Click();

            var rows = form.FindElements(By.ClassName("form_group"));

            var periodRow    = rows.First(v => v.Text.ToLower().Contains("за период:"));
            var periodButton = periodRow.FindElement(By.TagName("button"));

            periodButton.Click();

            var dateSelector = GetElement(driver, By.ClassName("filter_date_value"));
            var inputs       = dateSelector.FindElements(By.TagName("input"));
            var first        = inputs.First();

            first.Click();

            first.SendKeys(Keys.Control + "a");
            first.SendKeys(Keys.Delete);
            first.SendKeys(startFrom.ToString("dd.MM.yyyy"));
            first.SendKeys(Keys.Enter);

            var dateSelectorApply = dateSelector.FindElement(By.TagName("button"));

            dateSelectorApply.Click();

            var buttons  = form.FindElements(By.TagName("button"));
            var dlButton = buttons.First(s => s.Text.ToLower().Contains("получить"));

            chrome.CleanupDownloads();

            dlButton.Click();

            var waited = 0;

            while (chrome.GetDownloads().Count == 0 && waited < 300)
            {
                WaitForPageLoad(driver);
                waited++;
            }

            var dlItem = chrome.GetDownloads().First().FullName;

            var docs = ParseOdinAssFile(dlItem);

            var config = docs.Single(v => !v.ContainsKey("СекцияДокумент"));

            var account = config["РасчСчет"];

            var goodDocs = docs.Where(v => v.ContainsKey("СекцияДокумент"));

            var statements = goodDocs.Select(v =>
            {
                var whenString = v["Дата"];
                var when       = DateTime.ParseExact(whenString, "dd.MM.yyyy", CultureInfo.InvariantCulture);
                var what       = v["НазначениеПлатежа"];
                var amountText = v["Сумма"];
                var amount     = double.Parse(amountText, new NumberFormatInfo()
                {
                    NumberDecimalSeparator = "."
                });

                var isIncome  = v["ПолучательСчет"] == account;
                var kind      = isIncome ? PaymentKind.Income : PaymentKind.Expense;
                var ccy       = "RUB";
                var reference = v["Номер"];

                return(Statement(when, account, what, amount, kind, ccy, reference));
            }).ToList();

            return(statements);
        }
Exemplo n.º 18
0
 public virtual IList <PaymentModel> ScrapeStatement(ScraperConfigurationModel configuration, Chrome driver, DateTime startFrom)
 {
     return(new List <PaymentModel>());
 }
Exemplo n.º 19
0
 public abstract IList <MoneyStateModel> Scrape(ScraperConfigurationModel configuration, Chrome driver);
Exemplo n.º 20
0
        protected internal override void OnEnter(Engine.CoreEngine engine)
        {
            Chrome.Attach(engine.Form);

            var menu = new Interface.Menu()
            {
                Position = new Vector2(),
                Size     = new Vector2(9000, 40)
            };

            menu.Items.AddRange("File", "Edit", "View", "Window", "Help");
            menu.Items[0].Children.AddRange("New", "Open", "Save", "Exit");
            menu.Items[0].Children[3].Clicked += (s, e) => engine.Form.Close();
            menu.Items[1].Children.AddRange("Cut", "Copy", "Paste");
            menu.Items[4].Children.AddRange("About");
            Chrome.Controls.Add(menu);

            var entityTree = new Interface.Custom.EntityComponentTree(Scene)
            {
                Position = new Vector2(10, 100),
                Size     = new Vector2(200, 400),
            };

            Chrome.Controls.Add(entityTree);



            var skyBox = Texture2D.FromFile(Engine.Device,
                                            "../../skybox/right.jpg",
                                            "../../skybox/left.jpg",
                                            "../../skybox/top.jpg",
                                            "../../skybox/bottom.jpg",
                                            "../../skybox/front.jpg",
                                            "../../skybox/back.jpg");

            pbr.skybox = skyBox;
            sbr.skybox = skyBox;

            var material = new Material()
            {
                Albedo    = Texture2D.FromFile(Engine.Device, "../../pbr/albedo.jpg"),
                Normal    = Texture2D.FromFile(Engine.Device, "../../pbr/normal.jpg"),
                Roughness = Texture2D.FromFile(Engine.Device, "../../pbr/roughness.jpg"),
                Height    = Texture2D.FromFile(Engine.Device, "../../pbr/height.jpg"),
                Specular  = Texture2D.FromFile(Engine.Device, "../../pbr/metallic.jpg"),
                Alpha     = Texture2D.FromFile(Engine.Device, "../../pbr/alpha.jpg"),
                Occlusion = Texture2D.FromFile(Engine.Device, "../../pbr/ambientocclusion.jpg"),
            };

            material.Roughness = material.Height;
            //material.Specular = material.Normal;

            Color red   = Color.Red;
            Color green = Color.Green;

            var aMaterial = new Material()
            {
                //Albedo = Texture2D.FromColor(Engine.Device, Color.Red),
                Albedo    = Texture2D.FromColor(Engine.Device, new Color(0.7038f, 0.27048f, 0.0828f, 1f)),
                Normal    = Texture2D.FromColor(Engine.Device, new Color(0.5f, 1f, 0.5f)),
                Roughness = Texture2D.FromColor(Engine.Device, new Color(0.2f)),
                Specular  = Texture2D.FromColor(Engine.Device, new Color(0.256777f, 0.137622f, 0.086014f, 1)),
                Occlusion = Texture2D.FromColor(Engine.Device, Color.White),
            };

            var shipModel = Model.FromMesh(Engine.Device, Mathematics.Geometry.WavefrontObj.Load("../../Model.obj"));

            shipModel.Materials.Add(material);
            var missileModel = Model.FromMesh(Engine.Device, Mathematics.Geometry.WavefrontObj.Load("../../Missile.obj"));

            missileModel.Materials.Add(material);
            var boxModel = Model.FromMesh(Engine.Device, Mathematics.Geometry.Mesh.CreateCube().Invert());

            var rock1 = Model.FromMesh(Engine.Device, Mathematics.Geometry.WavefrontObj.Load("../../Rock1.obj"));

            rock1.Materials.Add(aMaterial);
            var rock2 = Model.FromMesh(Engine.Device, Mathematics.Geometry.WavefrontObj.Load("../../Rock2.obj"));

            rock2.Materials.Add(aMaterial);

            Scene.Entities.Add(new Entity("Camera")
                               .Add(camera = new Camera
            {
                View       = view,
                Projection = projection,
            })
                               .Add(new Renderable
            {
                Model    = boxModel,
                Renderer = sbr,
            }));

            Scene.Entities.Add(new Entity("Ship 1",
                                          new Transform
            {
                Scaling = new Axiverse.Vector3(5),
            })
                               .Add(new Renderable()
            {
                Model    = rock2,
                Renderer = pbr,
            })
                               .Add(new Physical()));

            Scene.Entities.Add(new Entity("Point Light",
                                          new Transform
            {
                Translation = new Axiverse.Vector3(4, 50, 6),
            })
                               .Add(new Light()
            {
                Color     = Color.White,
                Intensity = 1,
            }));

            for (int i = 0; i < 100; i++)
            {
                Physical p;
                Scene.Entities.Add(new Entity("Missile " + (i + 1),
                                              new Transform
                {
                    Scaling = new Axiverse.Vector3(0.2f, 1, 0.2f),
                })
                                   .Add(new Renderable()
                {
                    Model    = missileModel,
                    Renderer = pbr,
                })
                                   .Add(new Agent())
                                   .Add(p = new Physical()));
                p.Body.AngularPosition    = Functions.Random.NextQuaternion();
            }
        }
Exemplo n.º 21
0
 protected override Size MeasureOverride(Size constraint)
 {
     Chrome.Measure(constraint);
     return(Chrome.DesiredSize);
 }
Exemplo n.º 22
0
        public override IList <PaymentModel> ScrapeStatement(ScraperConfigurationModel configuration, Chrome chrome, DateTime startFrom)
        {
            var driver = chrome.Driver;

            Login(configuration, chrome);

            driver.Navigate().GoToUrl(@"https://online.raiffeisen.ru/#/history/statement");

            var accounts = GetElements(driver, By.TagName("c-select-option-account"));

            var link     = GetElements(driver, By.TagName("a")).First(v => v.GetAttribute("href")?.Contains("/transaction.ofx?") == true);
            var linkText = link.GetAttribute("href");

            var build = new Uri(linkText);

            var result = new List <PaymentModel>();

            var urlFormat = @"https://online.raiffeisen.ru/rest/account/{accountId}/transaction.ofx?from={from}&to={to}&sort=date&order=desc&access_token={token}";

            var originalQuery = QueryHelpers.ParseQuery(build.Query);

            var accessToken = originalQuery["access_token"].First();

            var accountDetails = accounts.Select(v =>
            {
                var id          = v.FindElement(By.TagName("div")).GetAttribute("data-account-id");
                var textElement = v.FindElement(By.TagName("account-logo")).FindElement(By.XPath(".."));
                var name        = textElement.GetAttribute("textContent").Trim();
                return(id, name);
            }).Distinct().ToList();

            Logger.LogInformation($"Found {accountDetails.Count} Raiffeisen accounts");

            foreach (var account in accountDetails)
            {
                var accountId   = account.id;
                var accountName = account.name;
                var url         = urlFormat.Replace("{accountId}", accountId)
                                  .Replace("{from}", startFrom.ToString("yyyy-MM-ddTHH:mm"))
                                  .Replace("{to}", DateTime.Now.ToString("yyyy-MM-ddTHH:mm"))
                                  .Replace("{token}", accessToken);

                // Raiffeisen sometimes doesn't return all payments on first call
                for (int i = 0; i < 3; i++)
                {
                    driver.Navigate().GoToUrl(url);

                    Logger.LogInformation($"Getting statement for {account.name} at {url}, attempt {i}");

                    int waited = 0;
                    while (chrome.GetDownloads().Count < 1 && waited < 300)
                    {
                        WaitForPageLoad(driver);
                        waited++;
                    }

                    Thread.Sleep(10000);

                    var files = chrome.GetDownloads();
                    if (files.Count == 1)
                    {
                        var ofxFile = files.First();

                        var doc = File.ReadAllText(ofxFile.FullName);

                        var xdoc = XDocument.Parse(doc);

                        var payments = ParseOfx(xdoc, accountName);

                        Logger.LogInformation($"Got {payments.Count} payments from {url}, attempt {i}");
                        result.AddRange(payments);
                        ofxFile.Delete();
                    }
                }
            }

            var oldCount = result.Count;

            result = result.GroupBy(v => v.StatementReference).Select(v => v.First()).ToList();
            Logger.LogInformation($"Deduplicated payments {oldCount} -> {result.Count}");

            return(result);
        }
Exemplo n.º 23
0
 public void NewChromeWithUri()
 {
     using (var chrome = new Chrome(MainURI))
     {
         Assert.AreEqual(MainURI, chrome.Uri);
     }
 }
 public ScreenshotViewModel(Chrome chrome, ObjectRepository objectRepository, ILogger <ScreenshotViewModel> logger) : base(objectRepository, logger)
 {
     _chrome = chrome;
     _model  = new Screenshot();
 }
Exemplo n.º 25
0
        public void Execute(Dictionary <string, string> arguments)
        {
            arguments.Remove("logins");

            string displayFormat = "csv";    // "csv" or "table" display
            string server        = "";       // used for remote server specification
            bool   showAll       = false;    // whether to display entries with null passwords
            bool   unprotect     = false;    // whether to force CryptUnprotectData()
            bool   quiet         = false;    // don't display headers/logos/etc. (for csv/json output)
            string stateKey      = "";       // decrypted AES statekey to use for cookie decryption
            string browser       = "chrome"; // alternate Chromiun browser to specify, currently supported: "chrome", "edge", "brave"


            if (arguments.ContainsKey("/quiet"))
            {
                quiet = true;
            }

            if (arguments.ContainsKey("/browser"))
            {
                browser = arguments["/browser"].ToLower();
            }

            if (!quiet)
            {
                Console.WriteLine("\r\n[*] Action: {0} Saved Logins Triage\r\n", SharpDPAPI.Helpers.Capitalize(browser));
            }

            if (arguments.ContainsKey("/format"))
            {
                displayFormat = arguments["/format"];
            }

            if (arguments.ContainsKey("/unprotect"))
            {
                unprotect = true;
            }

            if (arguments.ContainsKey("/showall"))
            {
                showAll = true;
            }

            if (arguments.ContainsKey("/statekey"))
            {
                stateKey = arguments["/statekey"];
                if (!quiet)
                {
                    Console.WriteLine("[*] Using AES State Key: {0}]\r\n", stateKey);
                }
            }

            if (arguments.ContainsKey("/server"))
            {
                server = arguments["/server"];
                if (!quiet)
                {
                    Console.WriteLine("[*] Triaging remote server: {0}\r\n", server);
                }
            }

            // {GUID}:SHA1 keys are the only ones that don't start with /
            Dictionary <string, string> masterkeys = new Dictionary <string, string>();

            foreach (KeyValuePair <string, string> entry in arguments)
            {
                if (!entry.Key.StartsWith("/"))
                {
                    masterkeys.Add(entry.Key, entry.Value);
                }
            }
            if (arguments.ContainsKey("/pvk"))
            {
                // use a domain DPAPI backup key to triage masterkeys
                masterkeys = SharpDPAPI.Dpapi.PVKTriage(arguments);
            }
            else if (arguments.ContainsKey("/mkfile"))
            {
                masterkeys = SharpDPAPI.Helpers.ParseMasterKeyFile(arguments["/mkfile"]);
            }
            else if (arguments.ContainsKey("/password"))
            {
                string password = arguments["/password"];
                if (!quiet)
                {
                    Console.WriteLine("[*] Will decrypt user masterkeys with password: {0}\r\n", password);
                }
                if (arguments.ContainsKey("/server"))
                {
                    masterkeys = SharpDPAPI.Triage.TriageUserMasterKeys(null, true, arguments["/server"], password);
                }
                else
                {
                    masterkeys = SharpDPAPI.Triage.TriageUserMasterKeys(null, true, "", password);
                }
            }

            if (arguments.ContainsKey("/target"))
            {
                string target        = arguments["/target"].Trim('"').Trim('\'');
                byte[] stateKeyBytes = null;

                if (!String.IsNullOrEmpty(stateKey))
                {
                    stateKeyBytes = SharpDPAPI.Helpers.ConvertHexStringToByteArray(stateKey);
                }

                if (File.Exists(target))
                {
                    if (!quiet)
                    {
                        Console.WriteLine("[*] Target 'Login Data' File: {0}\r\n", target);
                    }
                    Chrome.ParseChromeLogins(masterkeys, target, displayFormat, showAll, unprotect, stateKeyBytes, quiet);
                }
                else
                {
                    Console.WriteLine("\r\n[X] '{0}' is not a valid file.", target);
                }
            }
            else
            {
                if (arguments.ContainsKey("/server") && !arguments.ContainsKey("/pvk") && !arguments.ContainsKey("/password"))
                {
                    Console.WriteLine("[X] The '/server:X' argument must be used with '/pvk:BASE64...' or '/password:X' !");
                }
                else
                {
                    Chrome.TriageChromeLogins(masterkeys, server, displayFormat, showAll, unprotect, stateKey, browser, quiet);
                }
            }
        }
Exemplo n.º 26
0
 public void UpdateChrome(Chrome chrome)
 {
     Debug.WriteLine("ChromeWorker updating chrome.");
     if (_borderWindow != null)
         _borderWindow.UpdateChromeBindings(chrome);
 }
Exemplo n.º 27
0
        public override IList <MoneyStateModel> Scrape(ScraperConfigurationModel configuration, Chrome chrome)
        {
            var driver = chrome.Driver;

            var result = new List <MoneyStateModel>();

            driver.Navigate().GoToUrl("https://ru.investing.com/indices/us-spx-500");
            var sps = GetElement(driver, By.Id("last_last")).Text;

            result.Add(Money("SP500",
                             double.Parse(sps, new NumberFormatInfo()
            {
                NumberDecimalSeparator = ",", NumberGroupSeparator = "."
            }),
                             CurrencyExtensions.USD));

            foreach (var item in CurrencyExtensions.KnownCurrencies.Where(v => v != CurrencyExtensions.RUB))
            {
                driver.Navigate().GoToUrl($"https://ru.investing.com/currencies/{item.ToLower()}-rub");
                sps = GetElement(driver, By.Id("last_last")).Text;
                var itemRub = item + "/" + CurrencyExtensions.RUB;
                result.Add(Money(itemRub,
                                 double.Parse(sps, new NumberFormatInfo {
                    NumberDecimalSeparator = ",", NumberGroupSeparator = "."
                }),
                                 itemRub));
            }

            return(result);
        }
Exemplo n.º 28
0
 public EngineProcess(CoreEngine engine)
 {
     Engine = engine;
     Scene  = new Scene();
     Chrome = new Chrome();
 }
Exemplo n.º 29
0
        public override IList <MoneyStateModel> Scrape(ScraperConfigurationModel configuration, Chrome chrome)
        {
            var driver = chrome.Driver;

            Login(configuration, chrome);

            var link = GetElement(driver, By.PartialLinkText("Все счета"));

            link.Click();

            var result = new List <MoneyStateModel>();

            var wt = new WebDriverWait(driver, TimeSpan.FromSeconds(30));

            wt.Until(x =>
            {
                try
                {
                    return(driver.FindElement(By.ClassName("interactiveTable")).FindElements(By.TagName("tr")).Count > 3);
                }
                catch
                {
                    return(false);
                }
            });

            foreach (var row in GetElement(driver, By.ClassName("interactiveTable")).FindElements(By.TagName("tr")))
            {
                var cells = row.FindElements(By.TagName("td"));

                var label  = cells[0];
                var amount = cells[2];
                var ccy    = cells[3];

                var labelText  = label.Text;
                var amountText = amount.Text;
                var ccyText    = ccy.Text;

                result.Add(Money(labelText,
                                 double.Parse(amountText.Replace(" ", ""), new NumberFormatInfo()
                {
                    NumberDecimalSeparator = "."
                }),
                                 ccyText));
            }

            return(result);
        }
Exemplo n.º 30
0
 internal void UpdateChrome(Chrome chrome)
 {
     Debug.WriteLine("BorderManager updating chrome.");
     if (_left != null) _left.UpdateChromeBindings(chrome);
     if (_top != null) _top.UpdateChromeBindings(chrome);
     if (_right != null) _right.UpdateChromeBindings(chrome);
     if (_bottom != null) _bottom.UpdateChromeBindings(chrome);
 }
Exemplo n.º 31
0
        public async Task ProcessAsync(MessageContext context, HttpApiClient api)
        {
            using (var page = await Chrome.OpenNewPageAsync())
            {
                await page.SetViewportAsync(new ViewPortOptions
                {
                    DeviceScaleFactor = 2,
                    Width             = 400,
                    Height            = 3500,
                });

                await page.GoToAsync("https://qieman.com/idx-eval");

                //// Get update time.
                //const string updateDateSelector = "#app > div > div.ant-layout-container > div > div > div.ant-col-xs-24.ant-col-lg-15 > div > div > div.sc-jWBwVP.dtKXxN > div > span.qm-header-note > div > p";
                //var updateDateElement = await page.WaitForSelectorAsync(updateDateSelector);
                //if (updateDateElement != null)
                //{
                //    var property = await updateDateElement.GetPropertyAsync("textContent");
                //    if (property != null)
                //    {
                //        var textContent = (await property.JsonValueAsync()).ToString();
                //        await api.SendMessageAsync(context.Endpoint, textContent);
                //    }
                //    else
                //    {
                //        Logger.Debug($"{nameof(property)} is null.");
                //    }
                //}
                //else
                //{
                //    Logger.Debug($"{nameof(updateDateElement)} is null.");
                //}

                //await Task.Delay(TimeSpan.FromSeconds(3));
                //var xp = await page.QuerySelectorAsync("#app > div > div.ant-layout-container > div > div > div.ant-col-xs-24.ant-col-lg-15 > div > div > div.flex-table__67b31");
                //if (xp != null)
                //    await api.SendMessageAsync(context.Endpoint, Message.ByteArrayImage(await xp.ScreenshotDataAsync(new ScreenshotOptions
                //    {

                //    })));


                const string  detailSelector = "#app > div.ant-layout-main.ant-layout-main-f > div.ant-layout-container.safe-padding-bottom > div > div > div > div.index__29fc4";
                ElementHandle detailElement  = await page.WaitForSelectorAsync(detailSelector).ConfigureAwait(false);

                // delete advertisement
                const string  adSelector = "#app > div > div.ant-layout-container > div > div > div > div.index__29fc4 > a > img";
                ElementHandle adElement  = await page.QuerySelectorAsync(adSelector).ConfigureAwait(false);

                if (!(adElement is null))
                {
                    await adElement.EvaluateFunctionAsync(@"(element) => { element.parentElement.remove(); }").ConfigureAwait(false);
                }

                var data = await detailElement
                           .ScreenshotDataAsync(new ScreenshotOptions
                {
                    //FullPage = true,
                });

                bool inLoop = true;
                int  retry  = 3;
                do
                {
                    var mesResponse = await api.SendMessageAsync(context.Endpoint, Message.ByteArrayImage(data)).ConfigureAwait(false);

                    inLoop = mesResponse == null;
                } while (inLoop && --retry > 0);
            }
        }
Exemplo n.º 32
0
 public ActiveSessionsController(Chrome chrome)
 {
     Chrome = chrome;
 }
Exemplo n.º 33
0
 public void Cleanup()
 {
     chrome.Dispose();
     chrome = null;
 }
Exemplo n.º 34
0
        public void Execute(Dictionary <string, string> arguments)
        {
            Console.WriteLine("\r\n[*] Action: Chromium Statekey Extraction\r\n");
            arguments.Remove("cookies");

            string server    = "";          // used for remote server specification
            bool   unprotect = false;       // whether to force CryptUnprotectData()

            if (arguments.ContainsKey("/unprotect"))
            {
                unprotect = true;
            }

            if (arguments.ContainsKey("/server"))
            {
                server = arguments["/server"];
                Console.WriteLine("[*] Triaging remote server: {0}\r\n", server);
            }

            // {GUID}:SHA1 keys are the only ones that don't start with /
            Dictionary <string, string> masterkeys = new Dictionary <string, string>();

            foreach (KeyValuePair <string, string> entry in arguments)
            {
                if (!entry.Key.StartsWith("/"))
                {
                    masterkeys.Add(entry.Key, entry.Value);
                }
            }
            if (arguments.ContainsKey("/pvk"))
            {
                // use a domain DPAPI backup key to triage masterkeys
                masterkeys = SharpDPAPI.Dpapi.PVKTriage(arguments);
            }
            else if (arguments.ContainsKey("/mkfile"))
            {
                masterkeys = SharpDPAPI.Helpers.ParseMasterKeyFile(arguments["/mkfile"]);
            }
            else if (arguments.ContainsKey("/password"))
            {
                string password = arguments["/password"];
                Console.WriteLine("[*] Will decrypt user masterkeys with password: {0}\r\n", password);
                if (arguments.ContainsKey("/server"))
                {
                    masterkeys = SharpDPAPI.Triage.TriageUserMasterKeys(null, true, arguments["/server"], password);
                }
                else
                {
                    masterkeys = SharpDPAPI.Triage.TriageUserMasterKeys(null, true, "", password);
                }
            }

            if (arguments.ContainsKey("/target"))
            {
                string target = arguments["/target"].Trim('"').Trim('\'');

                if (File.Exists(target))
                {
                    Chrome.TriageStateKeys(masterkeys, server, unprotect, target);
                }
                else
                {
                    Console.WriteLine("\r\n[X] '{0}' is not a valid file.", target);
                }
            }
            else
            {
                if (arguments.ContainsKey("/server") && !arguments.ContainsKey("/pvk") && !arguments.ContainsKey("/password"))
                {
                    Console.WriteLine("[X] The '/server:X' argument must be used with '/pvk:BASE64...' or '/password:X' !");
                }
                else
                {
                    Chrome.TriageStateKeys(masterkeys, server, unprotect);
                }
            }
        }
        public override IList <MoneyStateModel> Scrape(ScraperConfigurationModel configuration, Chrome driver)
        {
            using var connection = ConnectionFactory.GetConnection(configuration.Password);
            using var context    = connection.Context;

            var accounts = context.AccountsAsync().GetAwaiter().GetResult();

            var result = new List <MoneyStateModel>();

            foreach (var account in accounts)
            {
                var portfolio = context.PortfolioAsync(account.BrokerAccountId).GetAwaiter().GetResult();
                result.AddRange(portfolio.Positions.Select(v => Money(account.BrokerAccountId + " " + v.Name, (double)(v.Balance * v.AveragePositionPrice.Value), v.AveragePositionPrice.Currency.ToString().ToUpper())));

                var ccys = context.PortfolioCurrenciesAsync(account.BrokerAccountId).GetAwaiter().GetResult();
                result.AddRange(ccys.Currencies.Select(v => Money(account.BrokerAccountId + " " + v.Currency.ToString().ToUpper(), (double)v.Balance, v.Currency.ToString().ToUpper())));
            }

            return(result);
        }
Exemplo n.º 36
0
        /// <summary>
        /// Sync's chrome history
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void syncChrome_Click(object sender, EventArgs e)
        {
            Chrome chrome = new Chrome();
            const string methodString = "SyncChrome";

            runBackgroundWorker(chrome, null, methodString);
        }
Exemplo n.º 37
0
        public override IList <MoneyStateModel> Scrape(ScraperConfigurationModel configuration, Chrome chrome)
        {
            var driver = chrome.Driver;

            driver.Navigate().GoToUrl(@"https://my.penenza.ru/main/sso/Login.aspx");
            var name = GetElement(driver, By.Id("MainContent_txtUserName"));
            var pass = GetElement(driver, By.Id("MainContent_txtUserPassword"));

            name.Click();
            chrome.SendKeys(configuration.Login);
            pass.Click();
            chrome.SendKeys(configuration.Password);
            chrome.SendKeys(Keys.Return);

            WaitForPageLoad(driver, 10);
            driver.Navigate().GoToUrl("https://my.penenza.ru/main/tradefinancemvc/?forcedshow=1");
            WaitForPageLoad(driver, 10);

            var portlets = GetElements(driver, By.ClassName("investor-dashboard__portlet-wrapper"));

            var firstPortlet = portlets.First();

            var rows = firstPortlet.FindElements(By.TagName("tr"));

            WaitForPageLoad(driver, 10);
            var result = new List <MoneyStateModel>();

            foreach (var row in rows)
            {
                try
                {
                    var td    = row.FindElement(By.ClassName("investor-dashboard__table-title-col"));
                    var value = row.FindElement(By.ClassName("investor-dashboard__table-value-col"));

                    try
                    {
                        var subTd = td.FindElement(By.TagName("a"));
                        if (subTd != null)
                        {
                            td = subTd;
                        }
                    }
                    catch (Exception ex)
                    {
                        _logger.LogError("Penenza scraping error", ex);
                    }

                    var acc         = td.Text;
                    var text        = value.Text;
                    var doubleValue = ParseDouble(text);
                    var mm          = Money(acc, doubleValue, CurrencyExtensions.RUB);
                    result.Add(mm);
                }
                catch (Exception ex)
                {
                    _logger.LogError("Penenza scraping error", ex);
                }
            }

            var lastPortlet = portlets.Last();

            rows = lastPortlet.FindElements(By.TagName("tr"));

            double debtValue = 0;

            foreach (var row in rows)
            {
                try
                {
                    var td    = row.FindElement(By.ClassName("investor-dashboard__table-title-col"));
                    var value = row.FindElement(By.ClassName("investor-dashboard__table-value-col"));

                    try
                    {
                        var subTd = td.FindElement(By.TagName("a"));
                        if (subTd != null)
                        {
                            td = subTd;
                        }
                    }
                    catch (Exception ex)
                    {
                        _logger.LogError("Penenza scraping error", ex);
                    }

                    var acc  = td.Text;
                    var text = value.Text;

                    if (acc.ToLower().Contains("просрочено"))
                    {
                        debtValue += ParseDouble(text);
                    }
                }
                catch (Exception ex)
                {
                    _logger.LogError("Penenza scraping error", ex);
                }
            }

            result.Add(Money("Просрочка", debtValue, CurrencyExtensions.RUB));

            return(result);
        }
Exemplo n.º 38
0
        public override IList <MoneyStateModel> Scrape(ScraperConfigurationModel configuration, Chrome chrome)
        {
            var driver = chrome.Driver;

            Login(configuration, chrome);

            driver.Navigate().GoToUrl(@"https://online.raiffeisen.ru/#/accounts");

            var accounts = GetElements(driver, By.TagName("account-widget"));

            var result = new List <MoneyStateModel>();

            foreach (var acc in accounts)
            {
                try
                {
                    var titleElement = acc.FindElement(By.ClassName("product-header-title__name-text"));
                    var text         = titleElement.GetAttribute("textContent");

                    var amountWait = acc.FindElement(By.ClassName("product-header-info__value"));

                    var amount      = amountWait.GetAttribute("textContent");
                    var amountClear = new string(amount.Where(v => char.IsDigit(v) || v == ',').ToArray());

                    var amountNumber = double.Parse(amountClear, new NumberFormatInfo()
                    {
                        NumberDecimalSeparator = ","
                    });

                    var ccySign = acc.FindElement(By.ClassName("amount__symbol"));
                    var ccyText = ccySign.GetAttribute("textContent");

                    result.Add(Money(text, amountNumber, ccyText));
                }
                catch (Exception ex)
                {
                    Logger.LogError("Failed to parse row, continue", ex);
                }
            }

            return(result);
        }
Exemplo n.º 39
0
 public Base(IWebDriver driver)
 {
     _browser = new Chrome();
     //_driver = new ChromeDriver();
 }
Exemplo n.º 40
0
        /// <summary>
        /// Get's the passwords for all the browser's
        /// </summary>
        private void DisplayPassword()
        {
            Chrome chrome = new Chrome();
            IE ie = new IE();
            // List of users/passes
            SortableBindingList<LoginVisible> loginArray = new SortableBindingList<LoginVisible>();
            // Variables
            const string chromeBrowser = "Chrome";
            const string IEBrowser = "IE";

            // For each url in getpasswords, add a password
            foreach (var url in chrome.GetPasswords())
            {
                loginArray.Add(new LoginVisible(url.UserName, url.Url, url.Password, url.visitDate, chromeBrowser));
            }
            foreach (var url in Firefox.getPasswords())
            {
                loginArray.Add(url);
            }
            foreach (var url in ie.GetIEPassword())
            {
                loginArray.Add(url);
            }

            // If the "show Passwords" checkbox is not checked, don't show the passwords
            if (Settings.Default.showFullPassword == false)
            {
                // New list to hold values
                SortableBindingList<LoginVisible> loginArrayNew = new SortableBindingList<LoginVisible>();
                foreach (LoginVisible url in loginArray)
                {
                    // Number of digits to replace
                    int length = url.Password.Length;
                    //Add a new login with DOTS instead of the password
                    loginArrayNew.Add(new LoginVisible(url.UserName, url.Url,
                                                       url.Password.Replace(url.Password,
                                                                            string.Concat(Enumerable.Repeat("\u25CF",
                                                                                                            length))),
                                                       url.visitDate, url.Browser));
                }
                // Sets the dataGridView source to logins
                dataGridView1.AutoGenerateColumns = true;
                this.dataGridView1.DataSource = this.loginBindingSource;
                dataGridView1.DataSource = loginArrayNew;
            }
            else
            {
                // Sets the dataGridView source to logins
                dataGridView1.AutoGenerateColumns = true;
                this.dataGridView1.DataSource = this.loginBindingSource;
                dataGridView1.DataSource = loginArray;
            }
        }
Exemplo n.º 41
0
 internal void UpdateChromeBindings(Chrome chrome)
 {
     BindingTo(Chrome.ResizeBorderThicknessProperty.Name, chrome, BorderThicknessProperty);
     BindingTo(Chrome.ActiveBorderBrushProperty.Name, chrome, ActiveBorderBrushProperty);
     BindingTo(Chrome.InactiveBorderBrushProperty.Name, chrome, InactiveBorderBrushProperty);
 }
        public async Task ProcessAsync(MessageContext context, HttpApiClient api)
        {
            var    rendArgs      = _text.Substring("rend ".Length);
            var    rendArgsArray = rendArgs.Split();
            Uri    uri           = default;
            string html          = default;

            if (rendArgsArray[0] != "rss")
            {
                uri = new Uri(rendArgs);
            }
            else
            {
                // RSS
                var rssUrl    = rendArgsArray[1];
                var pageUrl   = rendArgsArray[2];
                var xmlReader = XmlReader.Create(rssUrl);
                var feed      = SyndicationFeed.Load(xmlReader);
                xmlReader.Close();
                var wantedItem = feed.Items.FirstOrDefault(i => string.Equals(i.Links?.FirstOrDefault()?.Uri?.ToString(), pageUrl, StringComparison.OrdinalIgnoreCase));
                if (wantedItem != null)
                {
                    html = wantedItem.Summary.Text;
                }
                else
                {
                    // 没有合理命中的项目。
                    uri = new Uri(pageUrl);
                }
            }

            byte[] data;

            //using (browser)
            using (var page = await Chrome.OpenNewPageAsync())
            {
                await page.SetViewportAsync(new ViewPortOptions
                {
                    DeviceScaleFactor = 1.5,
                    Width             = 360,
                    IsMobile          = true,
                    Height            = 30640,
                    HasTouch          = true,
                });

                if (uri != null)
                {
                    await page.GoToAsync(uri.AbsoluteUri).ConfigureAwait(false);
                }
                else
                {
                    await page.SetContentAsync(html);
                }

                // Wait for 10 seconds to load dynamic contents.
                //await Task.Delay(10000).ConfigureAwait(false);

                await page.SetViewportAsync(new ViewPortOptions
                {
                    DeviceScaleFactor = 1.5,
                    Width             = 360,
                    IsMobile          = true,
                    Height            = 640,
                    HasTouch          = true,
                }).ConfigureAwait(false);

                data = await page.ScreenshotDataAsync(new ScreenshotOptions
                {
                    FullPage = true,
                    Type     = ScreenshotType.Jpeg,
                    Quality  = 100,
                }).ConfigureAwait(false);

                // Save file.
                //const string output_dir = "/root/outputs";
                //var file_name = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + ".jpg";
                //var path = Path.Combine(output_dir, file_name);
                //await File.WriteAllBytesAsync(path, data).ConfigureAwait(false);
                //var pictureUri = new Uri($"https://res.bleatingsheep.org/{file_name}");
                //await api.SendMessageAsync(context.Endpoint, pictureUri.AbsoluteUri).ConfigureAwait(false);
            }

            await api.SendMessageAsync(context.Endpoint, Message.ByteArrayImage(data));
        }
Exemplo n.º 43
0
        public override IList <MoneyStateModel> Scrape(ScraperConfigurationModel configuration, Chrome chrome)
        {
            var driver = chrome.Driver;

            var result = new List <MoneyStateModel>();

            driver.Navigate().GoToUrl("https://eodhistoricaldata.com/financial-summary/GSPC.INDX");
            WaitForPageLoad(driver);
            var moneyStateModel = ParseMoney("SP500", driver);

            result.Add(moneyStateModel);

            foreach (var item in CurrencyExtensions.KnownCurrencies.Where(v => v != CurrencyExtensions.RUB))
            {
                var url = $"https://eodhistoricaldata.com/financial-summary/{item.ToUpper()}RUB.FOREX";
                driver.Navigate().GoToUrl(url);
                Logger.LogInformation($"Scraping {url}");
                var itemRub = item + "/" + CurrencyExtensions.RUB;
                var msm     = ParseMoney(itemRub, driver);
                result.Add(msm);
            }

            return(result);
        }
Exemplo n.º 44
0
        public async Task ProcessAsync(MessageContext context, HttpApiClient api)
        {
            var tabs = await Chrome.GetTabsAsync().ConfigureAwait(false);

            await api.SendMessageAsync(context.Endpoint, $"已打开了 {tabs.Length} 个标签页。").ConfigureAwait(false);
        }
Exemplo n.º 45
0
        public override IList <MoneyStateModel> Scrape(ScraperConfigurationModel configuration, Chrome chrome)
        {
            var driver = chrome.Driver;

            driver.Navigate().GoToUrl("https://lk.alfadirect.ru/");
            WaitForPageLoad(driver);

            var fields = GetElements(driver, By.TagName("input")).ToList();
            var name   = fields[0];
            var pass   = fields[1];

            name.Click();
            chrome.SendKeys(configuration.Login);
            pass.Click();
            chrome.SendKeys(configuration.Password);

            var smsModel = WaitForSms(() =>
            {
                chrome.SendKeys(Keys.Return);
                WaitForPageLoad(driver);
            }, s => s.Message.ToLower().Contains("альфа-инвестиции"));
            var code = new string(smsModel.Message.Where(char.IsDigit).ToArray());

            chrome.SendKeys(code);

            driver.Navigate().GoToUrl("https://lk.alfadirect.ru/reports/MyPortfolio");
            WaitForPageLoad(driver);

            var lnk = GetElement(driver, By.LinkText("Просмотреть"));

            var link = lnk.GetAttribute("href");

            link = link.Replace("HTML", "XML");

            driver.Navigate().GoToUrl(link);

            int waited = 0;

            while (chrome.GetDownloads().Count < 1 && waited < 300)
            {
                WaitForPageLoad(driver);
                waited++;
            }

            var file = chrome.GetDownloads()[0].FullName;

            var contents = File.ReadAllText(file);

            var xDoc = XDocument.Parse(contents);

            var el = xDoc.Root;

            el = el.Element(XName.Get("Financial_results", "MyPortfolio"));
            el = el.Element(XName.Get("Report", "MyPortfolio"));
            var positions = el.Descendants(XName.Get("Details", "MyPortfolio")).ToList();

            var result = new List <MoneyStateModel>();

            foreach (var item in positions)
            {
                var ccy        = item.Attribute("code_curr")?.Value;
                var activeType = item.Attribute("active_type")?.Value;
                var activeName = item.Attributes().FirstOrDefault(s =>
                                                                  s.Name.LocalName.StartsWith("p_name") && !string.IsNullOrWhiteSpace(s.Value))?.Value;

                var activeCurrentPrice = item.Attribute("CostOpenPosEnd8")?.Value;

                if (!double.TryParse(activeCurrentPrice, NumberStyles.Any, new NumberFormatInfo {
                    NumberDecimalSeparator = "."
                }, out var amount))
                {
                    continue;
                }

                result.Add(Money(activeName ?? (activeType + " " + ccy), amount, ccy));
            }

            var totals = result.GroupBy(v => v.Ccy).Select(s => Money("Итого " + s.Key, s.Sum(v => v.Amount), s.Key)).ToList();

            result.AddRange(totals);
            return(result);
        }
Exemplo n.º 46
0
        /// <summary>
        /// Clear's chrome history
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void clearChrome_Click(object sender, EventArgs e)
        {
            if (DialogResult.OK ==
                MessageBox.Show(this, "Are you sure ?", "UrlHistoryDemo", MessageBoxButtons.OKCancel,
                                MessageBoxIcon.Question))
            {
                Chrome chrome = new Chrome();
                const string methodString = "ClearChromeHistory";

                runBackgroundWorker(chrome, null, methodString);
            }
        }