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()); }
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(" ", "").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("任务完成"); }