/// <summary> /// 生成目录 /// </summary> /// <param name="book"></param> public string UploadIndexFile(TygModel.书名表 book) { string dirserver = string.Format(createDirUrl, System.IO.Path.GetDirectoryName("/" + book.GetHTMLFilePath())); //创建目录 string dic = GetWebDic(dirserver); //生成目录成功 if (!string.IsNullOrEmpty(dic)) { //生成没有成功 //移动当前工作目录 ftp.GotoDirectory(BaseFtpDic + Book.GetHTMLFilePath().Replace("/index.html", string.Empty), true); string dirindex = BaseWebSite + "HTML/" + Book.分类标识.Trim().ToPingYing() + "/" + Book.书名.Trim().ToPingYing() + "/index.html"; //ftp上传文件 if (Upload(dirindex)) { System.Console.WriteLine(string.Format("FTP {0},生成目录---------完成", Book.书名)); } } return(dic); }
/// <summary> /// 开始运行数据 /// </summary> public void Run(Action callBack, TygModel.书名表 book) { //数据无效直接返回 if (book == null) { return; } //记时器 System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch(); System.Threading.Tasks.Task task = System.Threading.Tasks.Task.Factory.StartNew(new Action(delegate { using (TygModel.Entities entity = new TygModel.Entities()) { var itembook = entity.书名表.Where(b => b.GUID == book.GUID).FirstOrDefault(); CreateBookHTML createbook = new CreateBookHTML(itembook); createbook.Run(); } //线程写文件时不锁会冲突 另一个文件正在使用的异常 lock (lockobj) { //采集完成一个记录一个 System.IO.File.AppendAllLines(ProgressFileName, new string[] { book.GUID.ToString() + ((char)2) + book.书名 }); } })); try { task.Wait(); task.Dispose(); } catch (Exception ex) { throw ex; } //进度加1 System.Threading.Interlocked.Increment(ref CurrentIndex); //输出当前进度 System.Console.WriteLine(string.Format("生成完成{0},用时:{1},进度:{2}/{3}", book.书名, Math.Round(watch.ElapsedMilliseconds / 1000.0 / 60, 2), CurrentIndex, books.Count)); watch.Stop(); //运行下一个数据 callBack(); }
/// <summary> /// 得到文章的内容 /// </summary> /// <param name="o">记录</param> /// <param name="entities">数据库操作实体</param> private void GetContents(TygModel.书名表 o, TygModel.Entities entities) { //得到 Skybot.Collections.Analyse.SingleListPageAnalyse ListPageAnalyse = null; Skybot.Collections.Analyse.XMLDocuentAnalyse documentAnalyse = null; //打印状态 System.Diagnostics.Debug.WriteLine("开始采集:" + o.书名 + " 目录:" + o.采集用的URL1); //得到转换后的对应分析器 List <Task> tasks = new List <Task>(); tasks.Add(Task.Factory.StartNew(() => { ListPageAnalyse = new Skybot.Collections.Analyse.SingleListPageAnalyse(o.采集用的URL1); documentAnalyse = new Skybot.Collections.Analyse.XMLDocuentAnalyse() { IndexPageUrl = new Skybot.Collections.Analyse.ListPageContentUrl() { index = 0, Title = o.书名, Url = new Uri(o.采集用的URL1) } }; try { //初始化内容分析器 documentAnalyse.GetPathExpression(documentAnalyse.IndexPageUrl, ListPageAnalyse.ListPageContentUrls); } catch (Exception) { } })); try { //等待添加页面列表分析完成 5 分钟没有完成则表示超时 System.Threading.Tasks.Task.WaitAll(tasks.ToArray(), TimeSpan.FromMinutes(5)); } catch (AggregateException ex) { ex.Handle((exx) => { System.Diagnostics.Debug.WriteLine(exx.Message + "|||||" + exx.StackTrace); return(true); }); } //如果数据有效 if (ListPageAnalyse != null && documentAnalyse != null && documentAnalyse.PathExpression != null) { //得到已经存在的记录 var docentitys = o.文章表.ToList(); var docs = docentitys.Select(p => p.章节名.Trim()); //打印状态 System.Diagnostics.Debug.WriteLine("内容共:" + ListPageAnalyse.ListPageContentUrls.Count + "条记录"); //将章节列表索引转换成为扩展实体数据 List <UrlExtentEntity> entitys = ListPageAnalyse.ListPageContentUrls.Select(p => new UrlExtentEntity() { index = p.index, Indexs = p.Indexs, Title = p.Title, Url = p.Url }).ToList(); //开始采集数据 for (int k = 0; k < entitys.Count; k++) { //上一条记录 UrlExtentEntity PreviousItem = null; // entitys[k - 1]; //当前记录 UrlExtentEntity CurrentItem = null; // entitys[k]; //下一条记录 UrlExtentEntity NextItem = null; // entitys[k + 1]; //当前记录 CurrentItem = entitys[k]; //看看记录是不是已经存在了 如果存在则不进行更新 if (!docs.Contains(CurrentItem.Title.Trim())) { #region 值 //上一条记录 if (k - 1 >= 0) { PreviousItem = entitys[k - 1]; //如果上一章节已经存在了则就用数据库中的记录 var Temprecords = docentitys.Where(p => p.章节名.Trim() == PreviousItem.Title.Trim()); if (Temprecords.Count() > 0) { PreviousItem.Token = Temprecords.ElementAt(0).本记录GUID.ToString(); //设置本记录ID CurrentItem.Token = Temprecords.ElementAt(0).一章.Value.ToString(); } } //下一条记录 if (k + 1 < entitys.Count) { NextItem = entitys[k + 1]; } #endregion //当前章节的GUID if (CurrentItem.Token.Length < 10) { CurrentItem.Token = Guid.NewGuid().ToString(); } //产生下一章节的GUID if (NextItem != null && NextItem.Token.Length < 10) { NextItem.Token = Guid.NewGuid().ToString(); //如果上一章节已经存在了则就用数据库中的记录 var Temprecords = docentitys.Where(p => p.章节名.Trim() == CurrentItem.Title.Trim()); if (Temprecords.Count() > 0) { NextItem.Token = Temprecords.ElementAt(0).一章.Value.ToString(); } } //得到内容 string content = ""; try { content = documentAnalyse.GetContent(CurrentItem.Url.GetWeb()); } catch { } //添加到数据库 entities.AddTo文章表(new TygModel.文章表() { GUID = o.GUID, 书名 = o.书名, 分类标识 = o.分类标识, 本记录GUID = Guid.Parse(CurrentItem.Token), 创建时间 = DateTime.Now, 分类名称 = o.分类表.分类名称, 章节名 = CurrentItem.Title, 一章 = PreviousItem == null ? Guid.Empty :Guid.Parse(PreviousItem.Token), 一章 = NextItem == null ? Guid.Empty : Guid.Parse(NextItem.Token), 最后访问时间 = DateTime.Now, 内容 = content, 采集用的URL1 = CurrentItem.Url.ToString() }); //打印状态 System.Diagnostics.Debug.WriteLine("采集内容:" + CurrentItem.Title + "成功,正文长度:" + content.Length); } else { //如果记录的内容比较少则更新内容 var Temprecords = docentitys.Where(p => p.章节名.Trim() == CurrentItem.Title.Trim()); if (Temprecords.Count() > 0) { //如果内容无效 if ( //中文小于6 string.Join("", System.Text.RegularExpressions.Regex.Matches(Temprecords.ElementAt(0).内容, @"[\u4e00-\u9fa5\d\w123456789~!!·#¥%……—*()——+/”》“‘’,;。、?,:…《]+[\u4e00-\u9fa5123456789~!!·#¥%……—*(!)——+/”》“‘,’\r\n;。、?,:…《]", System.Text.RegularExpressions.RegexOptions.Multiline) .Cast <System.Text.RegularExpressions.Match>().Select(p => p.Value).ToArray() ).Length < 6 ) { //更新记录 var reccords = o.文章表.Where(p => p.章节名.Trim() == CurrentItem.Title.Trim()); if (reccords.Count() > 0) { var record = reccords.ElementAt(0); try { record.采集用的URL1 = CurrentItem.Url.ToString(); record.内容 = documentAnalyse.GetContent(CurrentItem.Url.GetWeb()); } catch { } //打印状态 System.Diagnostics.Debug.WriteLine("更新记录:" + CurrentItem.Title + "成功,正文长度:" + record.内容.Length); } } } } } } }
/// <summary> /// 创建一个新的书本采集实例 /// </summary> /// <param name="book">书</param> public CreateBookHTML(TygModel.书名表 book) { Book = book; //初始化进度文件 ProgressFileName = ProgressFileName + book.GUID + ".txt"; }
/// <summary> /// 转换数据 /// </summary> /// <returns></returns> public override TygModel.书名表 Convert() { DateTime updateTime; DateTime.TryParse(更新, out updateTime); TygModel.书名表 book = null; //看看分类表里有没有这个分类如果没有则进行分类添加 using (TygModel.Entities tygdb = new TygModel.Entities()) { //分类表 var classItems = tygdb.分类表.Where(p => p.分类名称.Trim() == 类别.Trim()); //当前分类 TygModel.分类表 classItem = null; //如果分类不存在 if (classItems.Count() == 0) { classItem = new TygModel.分类表() { 分类标识 = 类别.Trim(), 分类名称 = 类别.Trim(), 分类说明 = 类别.Trim(), 备注 = "来自 yankuaikan.com", 通用分类 = 类别.Trim() }; tygdb.AddTo分类表(classItem); //保存分类 tygdb.SaveChanges(); } else { classItem = classItems.FirstOrDefault(); } book = new TygModel.书名表() { 分类表 = classItem, 分类标识 = classItem.分类标识, 分类表ID = classItem.ID, GUID = Guid.NewGuid(), 采集用的URL1 = 小说目录URL, 采集用的URL2 = 小说简介URL, 创建时间 = DateTime.Now, 最新章节 = 最新章节, 作者名称 = 作者, 说明 = "", 书名 = 小说名称.Replace("》", "").Replace("《", ""), 最后更新时间 = updateTime, 完本 = 状态.Trim() == "完成" ? true : false, 配图 = new Func <string>(() => { if (小说简介URL != null) { //初始化一个DOM HtmlAgilityPack.HtmlDocument dom = new HtmlAgilityPack.HtmlDocument(); dom.LoadHtml(小说简介URL.GetWeb()); //内容 HtmlAgilityPack.HtmlNode listContent = dom.GetElementbyId("content"); //可能的原素 List <PossiblyResultElement> possiblyResultElements = new List <PossiblyResultElement>(); //开始循环子原素 SingleListPageAnalyse.AnalyseMaxATagNearest(listContent, possiblyResultElements, 0, new PossiblyResultElement() { ParentPossiblyResult = null, CurrnetHtmlElement = listContent, LayerIndex = -1, ContainTagNum = 0 }); //计算当前所有HTML原素中的img原素 var PageimgElements = from img in possiblyResultElements where img.CurrnetHtmlElement.Name == "a" && img.CurrnetHtmlElement.HasChildNodes && img.CurrnetHtmlElement.ChildNodes.Where(p => p.Name == "img").Count() > 0 select img; try { if (PageimgElements.Count() > 0) { //img.CurrnetHtmlElement.Attributes["src"].Value.Contains("http://tu.yankuai.com") && img.CurrnetHtmlElement.Attributes["src"] != null string imgurl = PageimgElements.First().CurrnetHtmlElement.ChildNodes[0].Attributes["src"].Value; return(imgurl.Trim().Contains("http://tu.yankuai.com") ? imgurl : "/images/noimg.jpg"); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(DateTime.Now + ex.Message + "|||||" + ex.StackTrace); } } //找到文章目录 return("/images/noimg.jpg"); }).Invoke(), }; } return(book); }
/// <summary> /// 转换数据 /// </summary> /// <returns></returns> public override TygModel.书名表 Convert() { DateTime updateTime = DateTime.Parse(更新); //书本 TygModel.书名表 book = null; //看看分类表里有没有这个分类如果没有则进行分类添加 using (TygModel.Entities tygdb = new TygModel.Entities()) { //分类表 var classItems = tygdb.分类表.Where(p => p.分类名称.Trim() == 类别.Trim()); //当前分类 TygModel.分类表 classItem = null; //如果分类不存在 if (classItems.Count() == 0) { try { classItem = new TygModel.分类表() { 分类标识 = 类别.Trim(), 分类名称 = 类别.Trim(), 分类说明 = 类别.Trim(), 备注 = "来自 www.xs52.com", 通用分类 = 类别.Trim() }; tygdb.AddTo分类表(classItem); //保存分类 tygdb.SaveChanges(); } catch (Exception ex) { System.Diagnostics.UDPGroup.SendStrGB2312(ex.Message + (ex.StackTrace != null ? ex.StackTrace : "")); } } else { classItem = classItems.FirstOrDefault(); } book = new TygModel.书名表() { 分类标识 = classItem.分类标识, 分类表ID = classItem.ID, GUID = Guid.NewGuid(), 采集用的URL1 = 小说目录URL, 采集用的URL2 = 小说简介URL, 创建时间 = DateTime.Now, 最新章节 = 最新章节, 作者名称 = 作者, 说明 = "", 书名 = 小说名称.Replace("》", "").Replace("《", ""), 最后更新时间 = updateTime, 完本 = 状态.Trim() == "连载" ? false : true, 配图 = "/images/noimg.gif", }; //修改配图或者说明 if (小说简介URL != null) { book.说明 = string.Format("小说《{0}》{1}/著", 小说名称, 作者); } } return(book); }
/// <summary> /// 创建一个新的书本采集实例 /// </summary> /// <param name="book">书</param> public CreateBookHTMLFTP(TygModel.书名表 book) : base(book) { }
protected void Page_Load(object sender, EventArgs e) { string url = string.Format(BaseUrl, "1"); //得到最大的页码 int MaxPageNum = 1; //初始化一个DOM HtmlAgilityPack.HtmlDocument dom = new HtmlAgilityPack.HtmlDocument(); dom.LoadHtml(url.GetWeb()); //内容 HtmlAgilityPack.HtmlNode listContent = dom.GetElementbyId("content"); //得到分页 HtmlAgilityPack.HtmlNode pagesNode = dom.GetElementbyId("pagelink"); #region 得到页面的所有tr原素 List <BookInfoYankuaikan_com> books = GetBookInfos(listContent, url); #endregion #region 提取 pages 中 所有的a原素 MaxPageNum = GetMaxPageNum(pagesNode); #endregion List <BookInfoYankuaikan_com> AllBooks = new List <BookInfoYankuaikan_com>(); //序列化保存为文件 System.Xml.Serialization.XmlSerializer ser = new System.Xml.Serialization.XmlSerializer(AllBooks.GetType()); //如果文件不存在则从缓存读取 if (!System.IO.File.Exists(yankuankanPath)) { AllBooks = GetBooks(MaxPageNum);//MaxPageNum System.IO.StringWriter sw = new System.IO.StringWriter(); ser.Serialize(sw, AllBooks); System.IO.File.WriteAllText(yankuankanPath, sw.ToString()); } else { AllBooks = (List <BookInfoYankuaikan_com>)ser.Deserialize(new System.IO.StringReader(System.IO.File.ReadAllText(yankuankanPath))); } //System.Threading.Tasks.Task.Factory.StartNew(new Action(delegate //{ //添加到Book中 for (int k = 0; k < AllBooks.Count; k++) { try { TygModel.书名表 book = AllBooks[k].Convert(); //当前记录 var records = Skybot.Cache.RecordsCacheManager.Instance.Tygdb.书名表.Where(p => p.书名.Trim() == book.书名.Trim() && p.作者名称.Trim() == book.作者名称.Trim()); if (records.Count() > 0) { //得到当前书更新记录 TygModel.书名表 currentBook = records.FirstOrDefault(); // currentBook.分类表 = book.分类表; //currentBook.分类表ID = book.分类表ID; //currentBook.GUID = book.GUID; currentBook.采集用的URL1 = book.采集用的URL1; currentBook.采集用的URL2 = book.采集用的URL2; // currentBook.创建时间 = book.创建时间; currentBook.最新章节 = book.最新章节; //currentBook.作者名称 = book.作者名称; currentBook.说明 = book.说明; // currentBook.书名 = book.书名; currentBook.最后更新时间 = book.最后更新时间; currentBook.完本 = book.完本; currentBook.配图 = book.配图; //保存更改 Skybot.Cache.RecordsCacheManager.Instance.Tygdb.SaveChanges(); } else { Skybot.Cache.RecordsCacheManager.Instance.Tygdb.AddTo书名表(book); //保存更改 Skybot.Cache.RecordsCacheManager.Instance.Tygdb.SaveChanges(); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message + (ex.StackTrace != null ? ex.StackTrace : "")); } System.Diagnostics.Debug.WriteLine("已经完成书" + k + "/" + AllBooks.Count); } //})); Response.Write("输入完成"); }
protected void Page_Load(object sender, EventArgs e) { Response.Write( Server.UrlDecode("http://www.trimedgas.com/error/error.aspx?Error='s'+%e9%99%84%e8%bf%91%e6%9c%89%e8%af%ad%e6%b3%95%e9%94%99%e8%af%af%e3%80%82%0d%0a%e5%85%b3%e9%94%ae%e5%ad%97+'with'+%e9%99%84%e8%bf%91%e6%9c%89%e8%af%ad%e6%b3%95%e9%94%99%e8%af%af%e3%80%82%e5%a6%82%e6%9e%9c%e6%ad%a4%e8%af%ad%e5%8f%a5%e6%98%af%e5%85%ac%e7%94%a8%e8%a1%a8%e8%a1%a8%e8%be%be%e5%bc%8f%e6%88%96+xmlnamespaces+%e5%ad%90%e5%8f%a5%ef%bc%8c%e9%82%a3%e4%b9%88%e5%89%8d%e4%b8%80%e4%b8%aa%e8%af%ad%e5%8f%a5%e5%bf%85%e9%a1%bb%e4%bb%a5%e5%88%86%e5%8f%b7%e7%bb%93%e5%b0%be%e3%80%82%0d%0a%e5%85%b3%e9%94%ae%e5%ad%97+'with'+%e9%99%84%e8%bf%91%e6%9c%89%e8%af%ad%e6%b3%95%e9%94%99%e8%af%af%e3%80%82%e5%a6%82%e6%9e%9c%e6%ad%a4%e8%af%ad%e5%8f%a5%e6%98%af%e5%85%ac%e7%94%a8%e8%a1%a8%e8%a1%a8%e8%be%be%e5%bc%8f%e6%88%96+xmlnamespaces+%e5%ad%90%e5%8f%a5%ef%bc%8c%e9%82%a3%e4%b9%88%e5%89%8d%e4%b8%80%e4%b8%aa%e8%af%ad%e5%8f%a5%e5%bf%85%e9%a1%bb%e4%bb%a5%e5%88%86%e5%8f%b7%e7%bb%93%e5%b0%be%e3%80%82%0d%0a%e5%85%b3%e9%94%ae%e5%ad%97+'with'+%e9%99%84%e8%bf%91%e6%9c%89%e8%af%ad%e6%b3%95%e9%94%99%e8%af%af%e3%80%82%e5%a6%82%e6%9e%9c%e6%ad%a4%e8%af%ad%e5%8f%a5%e6%98%af%e5%85%ac%e7%94%a8%e8%a1%a8%e8%a1%a8%e8%be%be%e5%bc%8f%e6%88%96+xmlnamespaces+%e5%ad%90%e5%8f%a5%ef%bc%8c%e9%82%a3%e4%b9%88%e5%89%8d%e4%b8%80%e4%b8%aa%e8%af%ad%e5%8f%a5%e5%bf%85%e9%a1%bb%e4%bb%a5%e5%88%86%e5%8f%b7%e7%bb%93%e5%b0%be%e3%80%82" ) ); var books = Skybot.Cache.RecordsCacheManager.Instance.Tygdb.书名表.ToList(); for (int classid = 1; classid <= 8; classid++) { System.Diagnostics.Debug.WriteLine("开始采集图书列表" + "http://www.86zw.com/Book/ShowBookList.aspx?tclassid=" + classid + "&page={0}"); var al = new Skybot.Collections.Sites.BookList86zw_com() { BaseUrl = "http://www.86zw.com/Book/ShowBookList.aspx?tclassid=" + classid + "&page={0}" }.DoWork(); //开始写入数据库 var AllBooks = from doc in al select doc; //添加到Book中 for (int k = 0; k < AllBooks.Count(); k++) { try { TygModel.书名表 book = AllBooks.ElementAt(k).Convert(); //当前记录 var records = books.Where(p => p.书名.Replace("》", "").Replace("《", "").Trim() == book.书名.Replace("》", "").Replace("《", "").Trim() && p.作者名称.Trim() == book.作者名称.Trim()); if (records.Count() > 0) { //得到当前书更新记录 TygModel.书名表 currentBook = records.FirstOrDefault(); // currentBook.分类表 = book.分类表; //currentBook.分类表ID = book.分类表ID; //currentBook.GUID = book.GUID; currentBook.采集用的URL1 = book.采集用的URL1; currentBook.采集用的URL2 = book.采集用的URL2; // currentBook.创建时间 = book.创建时间; currentBook.最新章节 = book.最新章节; //currentBook.作者名称 = book.作者名称; currentBook.说明 = book.说明; // currentBook.书名 = book.书名; currentBook.最后更新时间 = book.最后更新时间; currentBook.完本 = book.完本; currentBook.配图 = book.配图; //保存更改 Skybot.Cache.RecordsCacheManager.Instance.Tygdb.SaveChanges(); } else { Skybot.Cache.RecordsCacheManager.Instance.Tygdb.AddTo书名表(book); Skybot.Cache.RecordsCacheManager.Instance.Tygdb.SaveChanges(); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message + (ex.StackTrace != null ? ex.StackTrace : "")); } System.Diagnostics.Debug.WriteLine("已经完成书" + k + "/" + AllBooks.Count()); } } System.Diagnostics.Debug.WriteLine("86zw 所有图书状态更新完成"); //更新书有效章节数量 TygModel.Entities enti = new TygModel.Entities(); var dd = enti.书名表.ToList(); dd = dd.Where(p => p.包含有效章节 == null || p.包含有效章节 == 0).ToList(); for (int k = 0; k < dd.Count(); k++) { dd.ElementAt(k).包含有效章节 = dd.ElementAt(k).文章表.Count; enti.SaveChanges(); } }
/// <summary> /// 转换数据 /// </summary> /// <returns></returns> public override TygModel.书名表 Convert() { DateTime updateTime = DateTime.Parse("2000-01-01"); //书本 TygModel.书名表 book = null; //看看分类表里有没有这个分类如果没有则进行分类添加 using (TygModel.Entities tygdb = new TygModel.Entities()) { //分类表 var classItems = tygdb.分类表.Where(p => p.分类名称.Trim() == 类别.Trim()); //当前分类 TygModel.分类表 classItem = null; //如果分类不存在 if (classItems.Count() == 0) { try { classItem = new TygModel.分类表() { 分类标识 = 类别.Trim(), 分类名称 = 类别.Trim(), 分类说明 = 类别.Trim(), 备注 = "来自 86zw.com", 通用分类 = 类别.Trim() }; tygdb.AddTo分类表(classItem); //保存分类 tygdb.SaveChanges(); } catch (Exception ex) { System.Diagnostics.UDPGroup.SendStrGB2312(ex.Message + (ex.StackTrace != null ? ex.StackTrace : "")); } } else { classItem = classItems.FirstOrDefault(); } book = new TygModel.书名表() { 分类表 = classItem, 分类标识 = classItem.分类标识, 分类表ID = classItem.ID, GUID = Guid.NewGuid(), 采集用的URL1 = 小说目录URL, 采集用的URL2 = 小说简介URL, 创建时间 = DateTime.Now, 最新章节 = 最新章节, 作者名称 = 作者, 说明 = "", 书名 = 小说名称.Replace("》", "").Replace("《", ""), 最后更新时间 = updateTime, 完本 = 状态.Trim() == "完结" ? true : false, 配图 = "/images/noimg.gif", }; //修改配图或者说明 if (小说简介URL != null) { System.Diagnostics.UDPGroup.SendStrGB2312("获取配图:" + 小说简介URL); //初始化一个DOM HtmlAgilityPack.HtmlDocument dom = new HtmlAgilityPack.HtmlDocument(); dom.LoadHtml(小说简介URL.GetWeb()); //信息说明字段 HtmlAgilityPack.HtmlNode DesriptionContent = dom.GetElementbyId("CrbtrTop"); //采集时间的xpath表达式 2011-11-18 HtmlAgilityPack.HtmlNode node = dom.DocumentNode.SelectSingleNode("/html[1]/body[1]/div[2]/div[2]/div[3]/div[2]/div[1]/ul[1]/li[6]"); if (node != null) { if (DateTime.TryParse(node.InnerText, out updateTime)) { book.最后更新时间 = updateTime; } } //说明 HtmlAgilityPack.HtmlNode summary = dom.GetElementbyId("CrbsSum"); if (summary != null) { book.说明 = summary.InnerHtml.Length > 4000 ? new Tong.TongUse().ForMatText(summary.InnerText, 0, 3800) : summary.InnerHtml; } //图片 HtmlAgilityPack.HtmlNode listContent = dom.GetElementbyId("CrbtlBookImg"); if (listContent != null) { //可能的原素 List <PossiblyResultElement> possiblyResultElements = new List <PossiblyResultElement>(); //开始循环子原素 SingleListPageAnalyse.AnalyseMaxATagNearest(listContent, possiblyResultElements, 0, new PossiblyResultElement() { ParentPossiblyResult = null, CurrnetHtmlElement = listContent, LayerIndex = -1, ContainTagNum = 0 }); //计算当前所有HTML原素中的img原素 var PageimgElements = from img in possiblyResultElements where img.CurrnetHtmlElement.Name == "img" select img; try { if (PageimgElements.Count() > 0) { string imgurl = PageimgElements.First().CurrnetHtmlElement.Attributes["src"].Value; if (!imgurl.ToLower().Contains("images/noimg.gif")) { try { imgurl = new Uri(new Uri(小说简介URL), imgurl).ToString(); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(DateTime.Now + ex.Message + "|||||" + ex.StackTrace); imgurl = "/images/noimg.gif"; } } System.Diagnostics.UDPGroup.SendStrGB2312("获取配图:" + 小说简介URL + " 完成" + imgurl); book.配图 = imgurl.Trim().Contains("/images/noimg.gif") ? "/images/noimg.gif" : imgurl; } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(DateTime.Now + ex.Message + "|||||" + ex.StackTrace); } } } } return(book); }