Beispiel #1
0
        private string prepareBook()
        {
            bool val = sf.isSafePull();

            if (!val)
            {
                while (!val)
                {
                    val = sf.isSafePull();
                }
                //break;
            }
            //string HTML = (wbBrowser.Document as mshtml.IHTMLDocument2).body.innerHTML;
            HtmlDocument doc = new HtmlDocument();

            doc.LoadHtml(this.Document.DocumentNode.OuterHtml);

            this.Document = doc;
            WebScraper.StartScrape scrape = new WebScraper.StartScrape(this.CurrentBook.PageType, doc);

            //string myString = File.ReadAllText(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\btth2.html");
            //HtmlDocument d = new HtmlDocument();
            //d.LoadHtml(myString);

            //WebScraper.StartScrape scrape = new WebScraper.StartScrape(this.CurrentBook.PageType, d);



            DatabaseWriter db = new DatabaseWriter(@"Server=localhost\SQLEXPRESS01; Database=Books; Trusted_Connection=true;");

            db.createSource(this.CurrentBook.AssociatedWebsite.WebsiteName, Websites.WuxiaWorld.WebsiteAddress);
            db.createBook(this.CurrentBook.BookName, this.CurrentBook.AssociatedWebsite.WebsiteName);
            db.createChapter(scrape.CurrentChapterName.Trim(), this.CurrentBook.BookName, scrape.BookContent, ProgramStatics.ChapterAddress, scrape.HTML);


            BookSaver saver = new BookSaver(this.CurrentBook.AssociatedWebsite.WebsiteName + "\\" + this.CurrentBook.BookName, scrape.CurrentChapterName.Trim());
            string    s     = scrape.BookContent;

            //s = replaceValues(s);
            //s.Trim();
            saver.saveBook(scrape.BookContent);


            if (string.IsNullOrEmpty(scrape.NextChapter))
            {
                ProgramStatics.NextBook = true;
                return("");
            }
            if (scrape.NextChapter.Equals("Page Not Found"))
            {
                ProgramStatics.NextBook = true;
                return("");
            }

            if (scrape.NextChapter.Equals(ProgramStatics.ChapterAddress) || scrape.NextChapter.Equals(ProgramStatics.PreviousChapter))
            {
                ProgramStatics.NextBook = true;
                return("");
            }
            ProgramStatics.PreviousChapter = ProgramStatics.ChapterAddress;
            ProgramStatics.ChapterAddress  = scrape.NextChapter;
            System.Threading.Thread.Sleep(2000);
            return(scrape.NextChapter);
        }
Beispiel #2
0
        private string prepareBook()
        {
            bool val = sf.isSafePull();

            if (!val)
            {
                while (!val)
                {
                    val = sf.isSafePull();
                }
                //break;
            }
            //string HTML = (wbBrowser.Document as mshtml.IHTMLDocument2).body.innerHTML;
            HtmlDocument doc = new HtmlDocument();

            doc.LoadHtml(this.Document.DocumentNode.OuterHtml);

            this.Document = doc;

            //WebScraper.PageTypes p = WebScraper.PageTypes[this.CurrentBook.SourceID];
            WebScraper.StartScrape scrape = new WebScraper.StartScrape(this.CurrentBook.SourceID, doc, this.CurrentBook.BookID);

            //Thread.Sleep(15000);

            string nextChapter     = scrape.NextChapter;
            string previousChapter = scrape.PreviousChapter;
            int    bookID          = this.CurrentBook.BookID;

            DatabaseWriter dbWrite = new DatabaseWriter();

            dbWrite.BookID = bookID;

            //dbWrite.ChapterAddress = Chapter;
            dbWrite.ChapterAddress = ProgramStatics.ChapterAddress;

            dbWrite.ChapterHtml            = scrape.HTML;
            dbWrite.ChapterName            = scrape.CurrentChapterName;
            dbWrite.ChapterText            = scrape.BookContent;
            dbWrite.PreviousChapterAddress = scrape.PreviousChapter;
            dbWrite.SaveChapter();

            Logging.Logging.LogMessage("", Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\Logs", "BookScraper_DBSaved",
                                       " BookID" + this.CurrentBook.BookID + "\r\n\r\n Book Next Chapter Address" + this.CurrentBook.NextChapterAddress + "\r\n\r\n Book Previous Chapter Address: " +
                                       this.CurrentBook.PreviousChapterAddress + "\r\n\r\n Book LastChapterAddress: " + this.CurrentBook.BookLastChapterAddress + "\r\n\r\n Book SourceID: " + this.CurrentBook.SourceID +
                                       "\r\n\r\n Chapter: " + this.Chapter + "\r\n\r\n DB Next Chapter Address: " + scrape.NextChapter + "\r\n\r\n DB Previous Chapter Address: " + scrape.PreviousChapter + "\r\n\r\n DB Chapter Name: " + scrape.CurrentChapterName);

            //DatabaseWriter db = new DatabaseWriter(@"Server=localhost\SQLEXPRESS; Database=Book; Trusted_Connection=true;");
            //db.createSource(this.CurrentBook.AssociatedWebsite.WebsiteName, Websites.WuxiaWorld.WebsiteAddress);
            //db.createBook(this.CurrentBook.BookName, this.CurrentBook.AssociatedWebsite.WebsiteName);
            //db.createChapter(scrape.CurrentChapterName, this.CurrentBook.BookName, scrape.BookContent, ProgramStatics.ChapterAddress, scrape.HTML);


            //BookSaver saver = new BookSaver(this.CurrentBook.AssociatedWebsite.WebsiteName + "\\" + this.CurrentBook.BookName, scrape.CurrentChapterName.Trim());



            BookSaver saver = new BookSaver(this.websites[this.CurrentBook.SourceID] + "\\" + this.CurrentBook.BookName, scrape.CurrentChapterName.Trim());
            string    s     = scrape.BookContent;

            //s = replaceValues(s);
            //s.Trim();
            //saver.saveBook(scrape.BookContent);

            /*
             * if (string.IsNullOrEmpty(scrape.NextChapter))
             *  return "";
             * if (scrape.NextChapter.Equals("Page Not Found"))
             *  return "";
             */
            if (scrape.NextChapter.Equals("Page Not Found") || scrape.NextChapter.Equals("Page Not Found/") || string.IsNullOrEmpty(scrape.NextChapter) || scrape.NextChapter.Equals(ProgramStatics.ChapterAddress) || scrape.NextChapter.Equals(ProgramStatics.PreviousChapter) || ChapterAlreadyExists(scrape.NextChapter))
            {
                ProgramStatics.NextBook = true;
                return("");
            }
            ProgramStatics.PreviousChapter = ProgramStatics.ChapterAddress;
            ProgramStatics.ChapterAddress  = scrape.NextChapter;
            //System.Threading.Thread.Sleep(15000);
            return(scrape.NextChapter);
        }