コード例 #1
0
        public void Fb2Element_Load_ValidNode_Works()
        {
            var fb2Element = new TextItem(); // fb2 counterpart of XText, plain text node

            var validNode = new XText("test content");

            fb2Element.Load(validNode);

            fb2Element.Content.Should().Be("test content");
        }
コード例 #2
0
        static void Main(string[] args)
        {
            Console.WriteLine(GetText());
            Console.ReadKey();

            Fb2Document fb2Document = Fb2Document.CreateDocument();
            var         options     = new ChromeOptions
            {
                //BinaryLocation = @"C:\Program Files\Google\Chrome Beta\Application\chrome.exe"
            };

            options.AddArgument("--log-level=3");
            options.AddArgument("--disable-logging");
            //options.AddArgument("--headless");

            var driver = new ChromeDriver(options)
            {
                Url = "https://author.today/"
            };

            if (!File.Exists("cookies"))
            {
                driver.FindElement(By.LinkText("Войти")).Click();
                input("Войдите в свой аккаунт, и нажмите *ENTER*");
                SaveCookies(driver.Manage().Cookies.AllCookies.ToArray());
            }
            else
            {
                driver.Manage().Cookies.DeleteAllCookies();
                foreach (var cookie in LoadCookies())
                {
                    driver.Manage().Cookies.AddCookie(cookie);
                }
                driver.Navigate().Refresh();
                SaveCookies(driver.Manage().Cookies.AllCookies.ToArray());
            }

            var bookId = input("Введите ссылку на книгу (https://author.today/work/119568)")
                         .Replace("https://", "")
                         .Replace("http://", "")
                         .Split('/')[2]
                         .intParse();

            driver.Navigate().GoToUrl($"https://author.today/reader/{bookId}");
again:
            Thread.Sleep(500);

            var fragments = driver.FindElements(By.XPath("//div[@class='text-container']//p"));

            foreach (var fragment in fragments)
            {
                Console.WriteLine($"{fragment.Text}\r\n");

                var textItem = new TextItem();
                textItem.Load(new XText(fragment.Text));

                var p = new Paragraph();
                p.Content.Add(textItem);

                var section = new BodySection();
                section.Content.Add(p);

                var body = new BookBody();
                body.Content.Add(section);

                fb2Document.Book.Content.Add(body);
            }

            File.WriteAllText("book.fb2", fb2Document.ToXmlString());

            try
            {
                driver.FindElement(By.XPath("//li[@class='next']//span[1]")).Click();
                goto again;
            }
            catch { }

            Console.ReadKey();
            driver.Close();
            driver.Quit();
            Environment.Exit(0);
        }
コード例 #3
0
ファイル: Card.cs プロジェクト: jimva3hj/hamqsler
 /// <summary>
 /// Load values for this Card from QslDnP card file contents
 /// </summary>
 /// <param name="itemNode">The Card node</param>
 /// <param name="culture">CultureInfo that the card was created in</param>
 private void LoadCard(XmlNode cardNode, CultureInfo culture)
 {
     XmlNode node = XmlProcs.GetFirstChildElement(cardNode);
     while(node != null)
     {
         switch(node.Name)
         {
             case "CardItem":
                 base.Load(node, culture);
                 QslCard = this;
                 // upper left corner of hamqsler cards always 0, 0
                 QslCard.DisplayX = 0;
                 QslCard.DisplayY = 0;
                 break;
             case "BackgroundImage":
                 BackImage = new BackgroundImage(true);
                 BackImage.Load(node, culture);
                 BackImage.QslCard = this;
                 break;
             case "SecondaryImage":
                 SecondaryImage sImage = new SecondaryImage();
                 sImage.Load(node, culture);
                 SecondaryImages.Add(sImage);
                 sImage.QslCard = this;
                 break;
             case "TextItem":
                 TextItem ti = new TextItem();
                 ti.Load(node, culture);
                 TextItems.Add(ti);
                 ti.QslCard = this;
                 break;
             case "QsosBox":
                 QsosBox = new QsosBox(true);
                 QsosBox.Load(node, culture);
                 QsosBox.QslCard = this;
                 break;
         }
         node = XmlProcs.GetNextSiblingElement(node);
     }
 }