/// <summary> /// 更新单本小说至数据库 /// </summary> /// <param name="_tfi">数据</param> /// <returns></returns> public static bool _b_Update_Fiction_Info(tb_fiction_info _tfi) { try { Cls_MySQLHelper <tb_fiction_info> _msh = new Cls_MySQLHelper <tb_fiction_info>(); MySqlContext context = _msh.DbContext(); context.Update(_tfi); _msh.Dispose_Db(); return(true); } catch { return(false); } }
public void TH_Get_Fiction_Info() { _4_ScrawlCore._0_BQG.Cls_HomePage _sc = new _4_ScrawlCore._0_BQG.Cls_HomePage(); string _s_URL = ""; _i_Success = 0; _i_Fail = 0; //获取爬取范围 this.BeginInvoke(new Action(() => { _i_Min_Val = (int)Nud_Min_Val.Value; _i_Max_Val = (int)Nud_Max_Val.Value; })); for (int i = _i_Min_Val; i < _i_Max_Val; i++) { _s_URL = string.Format("https://www.qu.la/book/{0}/", i); Show_Msg("开始爬取编号为【" + i + "】的小说信息,地址:" + _s_URL, 0); tb_fiction_info _tfi = _sc._o_Get_Fiction_Info(_s_URL); if (_tfi != null) { Show_Msg("爬取成功,小说名:《" + _tfi.col_fiction_name + "》,准备写入数据库;", 1); if (_1_DAL.Cls_Fiction_Info._b_Insert_Fiction_Info(_tfi)) { Show_Msg("写入数据库成功!", 1); _i_Success += 1; } else { Show_Msg("写入数据库失败!", 2); _i_Fail += 1; } } else { Show_Msg("爬取失败!", 2); _i_Fail += 1; } } Show_Msg(string.Format("爬取完成!成功【{0}】条,失败【{1}】条。", _i_Success, _i_Fail), 0); }
/// <summary> /// 根据关键词获取小说列表 /// </summary> /// <returns></returns> public List <tb_fiction_info> _o_Get_Fiction_Info_By_KeyWord() { //判断关键字 if (_str_KeyWord == "") { return(null); } List <tb_fiction_info> _ltfi_ret = new List <tb_fiction_info>(); HtmlWeb _web_Main = new HtmlWeb(); _web_Main.OverrideEncoding = Encoding.UTF8; try { HtmlAgilityPack.HtmlDocument _doc_Main = new HtmlAgilityPack.HtmlDocument(); _doc_Main = _web_Main.Load(_url_Search + _str_KeyWord); //判断是否有数据 if (_doc_Main.Text == "") { return(null); } //获取查询列表 HtmlNodeCollection _hnc_Search_List = _doc_Main.DocumentNode.SelectNodes("//div[starts-with(@class,'search-list')]/ul/li"); //查询列表第一项为表头,所有查询项数据需要大于1 if (_hnc_Search_List.Count == 1) { return(null); } //移除表头 _hnc_Search_List.RemoveAt(0); foreach (HtmlNode _hn in _hnc_Search_List) { HtmlAgilityPack.HtmlDocument _doc_One = new HtmlAgilityPack.HtmlDocument(); _doc_One.LoadHtml(_hn.InnerHtml); tb_fiction_info _tfi = new tb_fiction_info(); //获取小说类型 HtmlNodeCollection _hnc_Fiction_Type = _doc_One.DocumentNode.SelectNodes("//span[starts-with(@class,'s1')]"); if (_hnc_Fiction_Type != null && _hnc_Fiction_Type.Count > 0) { _tfi.col_fiction_type = _hnc_Fiction_Type[0].InnerText.Replace("[", "").Replace("]", ""); } //获取小说名称及主页链接 HtmlNodeCollection _hnc_Fiction_Name_URL = _doc_One.DocumentNode.SelectNodes("//span[starts-with(@class,'s2')]/a"); if (_hnc_Fiction_Name_URL != null && _hnc_Fiction_Name_URL.Count > 0) { _tfi.col_fiction_name = _hnc_Fiction_Name_URL[0].InnerText.Trim(); _tfi.col_url_homepage = _hnc_Fiction_Name_URL[0].Attributes["href"].Value; } //获取最新章节及链接 HtmlNodeCollection _hnc_Update_Chapter_URL = _doc_One.DocumentNode.SelectNodes("//span[starts-with(@class,'s3')]/a"); if (_hnc_Update_Chapter_URL != null && _hnc_Update_Chapter_URL.Count > 0) { _tfi.col_update_chapter = _hnc_Update_Chapter_URL[0].InnerText; _tfi.col_update_chapter_url = _hnc_Update_Chapter_URL[0].Attributes["href"].Value; } //获取小说作者 HtmlNodeCollection _hnc_Fiction_Author = _doc_One.DocumentNode.SelectNodes("//span[starts-with(@class,'s4')]"); if (_hnc_Fiction_Author != null && _hnc_Fiction_Author.Count > 0) { _tfi.col_fiction_author = _hnc_Fiction_Author[0].InnerText; } //获取点击数 HtmlNodeCollection _hnc_Click_Count = _doc_One.DocumentNode.SelectNodes("//span[starts-with(@class,'s5')]"); if (_hnc_Click_Count != null && _hnc_Click_Count.Count > 0) { _tfi.col_click_count = _hnc_Click_Count[0].InnerText; } //获取更新时间 HtmlNodeCollection _hnc_Update_Time = _doc_One.DocumentNode.SelectNodes("//span[starts-with(@class,'s6')]"); if (_hnc_Update_Time != null && _hnc_Update_Time.Count > 0) { _tfi.col_update_time = DateTime.Parse(_hnc_Update_Time[0].InnerText); } //获取小说状态 HtmlNodeCollection _hnc_Fiction_Stata = _doc_One.DocumentNode.SelectNodes("//span[starts-with(@class,'s7')]"); if (_hnc_Fiction_Stata != null && _hnc_Fiction_Stata.Count > 0) { _tfi.col_fiction_stata = _hnc_Fiction_Stata[0].InnerText; } _tfi.col_fiction_source = "笔趣阁"; _ltfi_ret.Add(_tfi); } return(_ltfi_ret); } catch { return(null); } }
/// <summary> /// 获取小说信息,包括章节,封皮 /// </summary> /// <param name="_tfi"></param> /// <returns></returns> public tb_fiction_detail_info _o_Get_Fiction_All_Info(tb_fiction_info _tfi) { if (_tfi == null) { return(null); } tb_fiction_detail_info _tfdi = new tb_fiction_detail_info(); _tfdi._tfi_Fiction = new tb_fiction_info(); _tfdi._ltcl_Chapter = new List <tb_chapter_list>(); HtmlWeb _web_Main = new HtmlWeb(); _web_Main.OverrideEncoding = Encoding.UTF8; try { HtmlAgilityPack.HtmlDocument _doc_Main = new HtmlAgilityPack.HtmlDocument(); _doc_Main = _web_Main.Load(_tfi.col_url_homepage); //判断是否有数据 if (_doc_Main.Text == "") { return(null); } //获取小说名 _tfdi._tfi_Fiction.col_fiction_name = _tfi.col_fiction_name; //小说主页链接 _tfdi._tfi_Fiction.col_url_homepage = _tfi.col_url_homepage; //获取小说信息 HtmlNodeCollection _hnc_Info = _doc_Main.DocumentNode.SelectNodes("//div[starts-with(@id,'maininfo')]/div[starts-with(@id,'info')]"); if (_hnc_Info.Count == 0) { return(null); } //获取小说作者 _tfdi._tfi_Fiction.col_fiction_author = _tfi.col_fiction_author; //获取最后更新时间 _tfdi._tfi_Fiction.col_update_time = _tfi.col_update_time; //获取最后更新章节及链接 _tfdi._tfi_Fiction.col_update_chapter = _tfi.col_update_chapter; _tfdi._tfi_Fiction.col_update_chapter_url = _tfi.col_update_chapter_url; //获取小说简介 HtmlNodeCollection _hnc_Intro = _doc_Main.DocumentNode.SelectNodes("//div[starts-with(@id,'maininfo')]/div[starts-with(@id,'intro')]"); if (_hnc_Intro.Count > 0) { _tfdi._tfi_Fiction.col_fiction_introduction = _hnc_Intro[0].InnerText.Trim(); } //小说封皮链接 HtmlNodeCollection _hnc_Poster_URL = _doc_Main.DocumentNode.SelectNodes("//div[starts-with(@id,'sidebar')]/div/img"); if (_hnc_Poster_URL.Count > 0) { _tfdi._tfi_Fiction.col_url_poster = "https://www.qu.la" + _hnc_Poster_URL[0].Attributes["src"].Value; } //设置来源 _tfdi._tfi_Fiction.col_fiction_source = "笔趣阁"; //获取点击量 _tfdi._tfi_Fiction.col_click_count = _tfi.col_click_count; //获取状态 _tfdi._tfi_Fiction.col_fiction_stata = _tfi.col_fiction_stata; //小说类型 _tfdi._tfi_Fiction.col_fiction_type = _tfi.col_fiction_type; //获取章节列表 HtmlNodeCollection _hnc_Chapter_List = _doc_Main.DocumentNode.SelectNodes("//div[starts-with(@id,'list')]/dl/dd/a"); if (_hnc_Chapter_List.Count != 0) { foreach (HtmlNode _hn in _hnc_Chapter_List) { tb_chapter_list _tcl_one = new tb_chapter_list(); _tcl_one.col_fiction_id = _tfi.col_fiction_id; _tcl_one.col_volume_id = 0; _tcl_one.col_chapter_name = _hn.InnerText; _tcl_one.col_chapter_url = _tfi.col_url_homepage + _hn.Attributes["href"].Value; _tfdi._ltcl_Chapter.Add(_tcl_one); } } //获取小说封皮 //链接有误 if (_tfdi._tfi_Fiction.col_url_poster != "") { _tfdi._img_Poster = Image.FromStream(WebRequest.Create(_tfdi._tfi_Fiction.col_url_poster) .GetResponse().GetResponseStream()); } return(_tfdi); } catch { return(null); } }
public Frm_Fiction_Detail_Info(tb_fiction_info _tfi) { InitializeComponent(); _tfi_Main = _tfi; _i_OpenType = 0; }
public List <tb_chapter_list> _b_Get_Chapter_List(tb_fiction_info _tfi) { _tfi_Main = _tfi; _url_Homepage = _tfi.col_url_homepage; return(_b_Get_Chapter_List()); }
public Cls_Get_Chapter_List(tb_fiction_info _tfi) { _tfi_Main = _tfi; _url_Homepage = _tfi.col_url_homepage; }
public tb_fiction_info _o_Get_Fiction_Info() { //判断链接是否存在 if (_url_Homepage == "") { return(null); } tb_fiction_info _tfi_ret = new tb_fiction_info(); HtmlWeb _web_Main = new HtmlWeb(); _web_Main.OverrideEncoding = Encoding.UTF8; try { HtmlAgilityPack.HtmlDocument _doc_Main = new HtmlAgilityPack.HtmlDocument(); _doc_Main = _web_Main.Load(_url_Homepage); //判断是否有数据 if (_doc_Main.Text == "") { return(null); } //获取小说名 HtmlNodeCollection _hnc_Title = _doc_Main.DocumentNode.SelectNodes("//div[starts-with(@id,'maininfo')]/div/h1"); if (_hnc_Title.Count == 0) { return(null); } _tfi_ret.col_fiction_name = _hnc_Title[0].InnerText; //小说主页链接 _tfi_ret.col_url_homepage = _url_Homepage; //获取小说信息 HtmlNodeCollection _hnc_Info = _doc_Main.DocumentNode.SelectNodes("//div[starts-with(@id,'maininfo')]/div[starts-with(@id,'info')]"); if (_hnc_Info.Count == 0) { return(null); } //获取小说作者 var _rg_Author = Regex.Matches(_hnc_Info[0].InnerHtml.Replace(" ", ""), @">作者:([^<]+)<"); if (_rg_Author.Count > 0) { _tfi_ret.col_fiction_author = _rg_Author[0].Value.Replace(">作者:", "") .Replace("<", ""); } //获取最后更新时间 var _rg_Update_Time = Regex.Matches(_hnc_Info[0].InnerText, @"最后更新:(\d{4})/(\d{1,2})/(\d{1,2}) (\d{1,2}):(\d{1,2}):(\d{1,2})"); if (_rg_Update_Time.Count > 0) { _tfi_ret.col_update_time = DateTime.Parse(_rg_Update_Time[0].Value.Substring(5)); } else { _rg_Update_Time = Regex.Matches(_hnc_Info[0].InnerText, @"最后更新:(\d{1,2})/(\d{1,2})/(\d{4}) (\d{1,2}):(\d{1,2}):(\d{1,2})"); if (_rg_Update_Time.Count > 0) { string[] _ls_Time = _rg_Update_Time[0].Value.Substring(5).Split(' '); string[] _ls_Time1 = _ls_Time[0].Split('/'); string _s_Full_Time = _ls_Time1[2] + "/" + _ls_Time1[0] + '/' + _ls_Time1[1] + " " + _ls_Time[1]; _tfi_ret.col_update_time = DateTime.Parse(_s_Full_Time); } } //获取最后更新章节及链接 HtmlNodeCollection _hnc_Chapter = _doc_Main.DocumentNode.SelectNodes("//div[starts-with(@id,'maininfo')]/div/p"); List <HtmlNode> _lhn_Chapter = _hnc_Chapter.Where(a => a.InnerText.Contains("最新更新")).ToList(); if (_lhn_Chapter.Count > 0) { //最新章节名 _tfi_ret.col_update_chapter = _lhn_Chapter[0].InnerText.Split(':')[1]; //最新章节链接 var _rg_Chapter_URL = Regex.Matches(_lhn_Chapter[0].InnerHtml.Replace(" ", ""), "href=\"([^\"]+)\""); if (_rg_Chapter_URL.Count > 0) { _tfi_ret.col_update_chapter_url = _url_Homepage + _rg_Chapter_URL[0].Value.Replace("href=\"", "") .Replace("\"", ""); } } //获取小说简介 HtmlNodeCollection _hnc_Intro = _doc_Main.DocumentNode.SelectNodes("//div[starts-with(@id,'maininfo')]/div[starts-with(@id,'intro')]"); if (_hnc_Intro.Count > 0) { _tfi_ret.col_fiction_introduction = _hnc_Intro[0].InnerText.Trim(); } //小说封皮链接 HtmlNodeCollection _hnc_Poster_URL = _doc_Main.DocumentNode.SelectNodes("//div[starts-with(@id,'sidebar')]/div/img"); if (_hnc_Poster_URL.Count > 0) { _tfi_ret.col_url_poster = "https://www.qu.la" + _hnc_Poster_URL[0].Attributes["src"].Value; } //设置来源 _tfi_ret.col_fiction_source = "笔趣阁"; } catch { return(null); } return(_tfi_ret); }