Ejemplo n.º 1
0
        private void BtnMulu_Click(object sender, EventArgs e)
        {
            //string cn = "第二八八章 危险的地方";
            //string num = Chinese2Num(cn);
            //listBox1.Items.Add(num);
            //return;
            string novalurl = txtNameURL.Text;

            //novalurl = "https://www.qb5.tw/shu/100487.html";
            if (string.IsNullOrWhiteSpace(novalurl))
            {
                AlertMessage("小说目录路径不能为空");
                return;
            }

            //抓取目录页面dom
            string html = HttpHelpr.HttpGet(novalurl, "", "1", "utf-8");

            string charset = DownFiles.GetEncode(html);

            if (charset != "utf-8")
            {
                html = HttpHelpr.HttpGet(novalurl, "", "1", charset);
            }

            string                      muluroot = DownFiles.GetMuluRoot(html);
            MatchCollection             sMC      = DownFiles.GetMulu(muluroot);
            Dictionary <string, string> list     = DownFiles.RemoteUrlList(sMC);

            foreach (var item in list)
            {
                listBox1.Items.Add(item.Value + DownFiles.Chinese2Num(item.Key));
            }
            AlertMessage("读取完成" + list.Count.ToString());
        }
Ejemplo n.º 2
0
        string path = "C://Noval//DownFile//" + DateTime.Now.ToString("yyyy-MM-dd") + "//";//AppDomain.CurrentDomain.BaseDirectory.Replace("\\", "/") + "DownFile/";
        private void Btn_StartRead_Click(object sender, EventArgs e)
        {
            //string str = "第二四零 这里我有些熟悉";
            //string msg=DownFiles.Chinese2Num(str);
            //MessageBox.Show(msg);
            //return;
            this.progressBar1.Maximum = 0;
            this.progressBar1.Value   = 0;
            txtDownDirectry.Text      = "";
            string novalurl = txtNameURL.Text;
            string xsname   = "我的小说" + DateTime.Now.ToString("yyyyMMddHHmmss");

            processNum = Convert.ToInt32(numericUpDown1.Value);
            if (processNum == 0)
            {
                processNum = 2;
            }
            if (string.IsNullOrWhiteSpace(novalurl))
            {
                Accomplish("小说目录路径不能为空");
                return;
            }

            //novalurl = "https://www.ddxsku.com/files/article/html/36/36102/index.html";
            //抓取整本小说
            string html = HttpHelpr.HttpGet(novalurl, "", "1", "utf-8");

            charset = DownFiles.GetEncode(html);
            if (charset != "utf-8")
            {
                html = HttpHelpr.HttpGet(novalurl, "", "1", charset);
            }
            string title = DownFiles.GetNovelName(html);

            xsname = string.IsNullOrEmpty(title) ? xsname : title;
            string          muluroot = DownFiles.GetMuluRoot(html);
            MatchCollection sMC      = DownFiles.GetMulu(muluroot);

            list  = DownFiles.RemoteUrlList(sMC);
            path1 = path + xsname + "//";
            if (list.Count != 0)
            {
                int taskCount = list.Count;
                this.progressBar1.Maximum = taskCount;
                this.progressBar1.Value   = 0;
                new Thread(ParallelFunction)
                {
                    IsBackground = true
                }.Start();
                txtDownDirectry.Text = path1;
            }
            else
            {
                Accomplish("没有提取到章节地址");
            }
        }
Ejemplo n.º 3
0
        public void ParallelFunction()
        {
            //多线程方式一:
            //Parallel.ForEach(list,(item,loopState)=>
            //{
            //    Thread.Sleep(1);
            //    //获取文章标题

            //    string title = item.Key.Replace("正文", "").Replace("_", "").Replace(" ", "").Replace("?", "").Replace("*", "").Replace(":", "");
            //    //获取文章内容
            //    string html_z = HttpHelpr.HttpGet(item.Value, "", "1",charset);
            //    // 获取正文
            //    Regex reg = new Regex(@"<dd id=""contents"">(.|\n)*?</dd>");
            //    var mat = reg.Match(html_z);
            //    if (string.IsNullOrEmpty(mat.Groups[0].ToString()))
            //    {
            //        reg = new Regex(@"<div id=""content(s?)"">(.|\n)*?</div>");
            //        mat= reg.Match(html_z);
            //    }
            //    string content = mat.Groups[0].ToString().Replace("<div id=\"content\">","").Replace("</div>", "").Replace("<dd id=\"contents\">", "").Replace("</dd>", "").Replace("&nbsp;", "").Replace("<br />", "\r\n");
            //    DownFiles.Novel(DownFiles.Chinese2Num(title) + "\r\n" + content, DownFiles.Chinese2Num(title), path);
            //    UpdataUIStatus(1);
            //});

            //多线程方式二:
            Parallel.For(0, list.Keys.Count,
                         new ParallelOptions()
            {
                MaxDegreeOfParallelism = processNum
            },
                         (i, loopState) =>
            {
                Thread.Sleep(1);

                //获取文章标题
                string title = list.Keys.ElementAt(i).Replace("正文", "").Replace("_", "").Replace("?", "").Replace("*", "").Replace(":", "");
                //获取文章内容
                string html_z = HttpHelpr.HttpGet(list[list.Keys.ElementAt(i)], "", "1", charset);
                // 获取正文
                string content = DownFiles.FindContent(html_z);
                // 获取章节序号
                string chartname = DownFiles.Chinese2Num(title);
                DownFiles.Novel(chartname + "\r\n" + content, chartname, path1);
                UpdataUIStatus(1);
            });
            Accomplish("任务完成");
        }