/// <summary> /// 通过传入html获取书籍信息的方法 /// </summary> /// <param name="html"></param> public void BookInfo(string html) { var htmlDoc = new HtmlAgilityPack.HtmlDocument(); htmlDoc.LoadHtml(html); try { for (int i = 0; i < 3; i++) { var name = htmlDoc.DocumentNode.SelectNodes("//div[@class='book-mid-info']//h4/a")[i]; //var info = htmlDoc.DocumentNode.SelectNodes("//div[@class='book-mid-info']//p [@class='intro']")[i]; var info = htmlDoc.DocumentNode.SelectNodes("//div[@class='book-mid-info']//h4//a")[i].Attributes["href"].Value; var image = htmlDoc.DocumentNode.SelectNodes("//div[@class='book-img-box']//img")[i].Attributes["src"].Value; if (Examine.IsNull(name.InnerText, BookIntro(info), image)) { bookInfo.Add(name.InnerText, BookIntro(info)); StreamFill(BookImage(name.InnerText, image), name.InnerText, BookIntro(info)); } else { throw new NoFound(); } } } catch { throw new NoFound(); } }
public void BookInfo(string html) { lock ("book") { var bookname = ""; var intro = ""; var id = 0; GetBookInfoByHtml getBookInfo = new GetBookInfoByHtml(); var htmlDoc = new HtmlAgilityPack.HtmlDocument(); htmlDoc.LoadHtml(html); try { for (int i = 0; i < 20; i++) { if (stop) { break; } var name = htmlDoc.DocumentNode.SelectNodes("//div[@class='book-mid-info']//h4/a")[i]; bookname = name.InnerText; var info = htmlDoc.DocumentNode.SelectNodes("//div[@class='book-mid-info']//h4//a")[i].Attributes["href"].Value; var image = htmlDoc.DocumentNode.SelectNodes("//div[@class='book-img-box']//img")[i].Attributes["src"].Value; if (Examine.IsNull(bookname, info, image)) { string path = ""; intro = getBookInfo.BookIntro(info); id = getBookInfo.BookImage(bookname, image); bookInfo.Add(bookname, intro); getBookInfo.StreamFill(id, bookname, intro); GetBookInfoByHtml.bookIDCover.TryGetValue(bookname, out path); getBookInfo.StreamAll(bookname, intro, path); this.Invoke(new Action(() => { lbInfo.Items.Add(bookname); })); } else { MessageBox.Show("未找到书籍!"); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } } }