Beispiel #1
0
        public static bool GetDownloadUrl(this BookInfo book, DependencyObject dispatcher = null)
        {
            if (book.ReadBookUrl == null || book.ReadBookUrl == "")
            {
                GetReadBookUrl(book);
            }
            string source = null;

            if (book.IsReadAll)
            {
                source = HttpWebResponseUtility.GetHtmlByWebBrowser(book.ReadBookUrl, dispatcher);
            }
            else
            {
                source = HttpWebResponseUtility.GetHtmlByHttpWebRequest(book.ReadBookUrl);
            }

            string regexStr = "did = \"(.*?)\"[\\s\\S]*?PdgPath = \"(.*?)\"[\\s\\S]*?var str = \"(.*?)\"";
            Match  m        = Regex.Match(source, regexStr);

            if (!m.Success)
            {
                throw new Exception("获取STR时出现错误!");
            }
            book.did     = m.Groups[1].Value;
            book.PdgPath = m.Groups[2].Value;
            String str = m.Groups[3].Value;

            if (!book.IsReadAll)
            {
                book.DownloadUrlTemp = String.Format(unreadableDownloadUrl, str, "{0}");
                string pid = null;
                try
                {
                    pid = BookDataBase.GetInstance().GetBookPID(book.DXID);
                }
                catch
                {
                    return(false);
                }
                string regex = @"img\d*/(.*?)/";
                m = Regex.Match(str, regex);
                if (pid != null && m.Success)
                {
                    book.DownloadUrl = book.DownloadUrlTemp.Replace(m.Groups[1].Value, pid);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                book.DownloadUrlTemp = String.Format(readableDownloadUrl, str, "{0}");
                book.DownloadUrl     = book.DownloadUrlTemp;
            }
            return(true);
        }
Beispiel #2
0
        public static String GetPdgHost(String did)
        {
            String source   = HttpWebResponseUtility.GetHtmlByHttpWebRequest(PdgPathSever);
            string regexStr = String.Format("<td>{0}</td><td>(.*?)</td>", did);
            Match  m        = Regex.Match(source, regexStr);

            if (m.Success)
            {
                return(m.Groups[1].Value);
            }
            else
            {
                return(null);
            }
        }
Beispiel #3
0
        public static void AddNewBook(this BookList booklist, String keyword, int page)
        {
            String url      = String.Format(Setting.searchUrl, UrlEncode(keyword), page);
            String regexStr = "url\" value=\"(.*?)\"[\\s\\S]*?封面 src='(.*?)'[\\s\\S]*?dxid\" value=\"(\\d*)[\\s\\S]*?ssid\" value=\"(\\d*)[\\s\\S]*?《(.*?)》</a>[\\s\\S]*?(/(?:gobaoku.jsp|readDetail.jsp).*?)\"[\\s\\S]*?(作者.*)";
            String html     = HttpWebResponseUtility.GetHtmlByHttpWebRequest(url);

            MatchCollection m = Regex.Matches(html, regexStr);

            m.AsParallel();
            booklist.GetMoreable = html.Contains("下一页");
            string[] s  = new string[10];
            Match[]  ms = new Match[m.Count];
            m.CopyTo(ms, 0);
            Parallel.ForEach(ms, match =>
            {
                booklist.addBook(GetBriefBookInfo(match.Groups));
            });
        }
Beispiel #4
0
        public static void GetReadBookUrl(this BookInfo book)
        {
            if (!book.IsReadAll)
            {
                book.ReadBookUrl = book.ReadBookUrlTemp;
                return;
            }
            string source   = HttpWebResponseUtility.GetHtmlByHttpWebRequest(book.ReadBookUrlTemp);
            string regexStr = @"window\.location\.href='(.*?)'";
            Match  m        = Regex.Match(source, regexStr);

            if (m.Success)
            {
                book.ReadBookUrl = m.Groups[1].Value;
            }
            else
            {
                throw new Exception("获取在线读地址时出现错误!");
            }
        }
Beispiel #5
0
        public static void GetDetailInfo(this BookInfo book)
        {
            if (book.isDetail)
            {
                return;
            }
            String coveReg = "(http://cover.*?)\"";
            string source  = HttpWebResponseUtility.GetHtmlByHttpWebRequest(book.DetailInfoUrl);
            Match  m       = Regex.Match(source, coveReg);

            if (m.Success)
            {
                book.BigCoverImage = HttpWebResponseUtility.GetImage(m.Groups[1].Value);
                book.isDetail      = true;
            }
            String regexStr = "<p>([\\s\\S]*?)</p>";

            m = Regex.Match(source, regexStr);
            while (m.Success)
            {
                book.DetailInfo += DataExtraction.RemoveHTMLTab(m.Groups[1].Value).Replace("\n", "").Replace("\r", "").Replace("\t", "").Replace(" ", "").Replace("&gt;", "->") + "\n";
                m = m.NextMatch();
            }
        }