public void Execute(IJobExecutionContext context) { //This method will run every 10 seconds which setted in JobScheduler class with following code //ITrigger trigger = TriggerBuilder.Create() //.WithIdentity("trigger1", "group1") //.StartNow() //.WithSimpleSchedule(x => x //.WithIntervalInSeconds(10) //.RepeatForever()) //.Build(); //GlobalMethod.log.Info("demojob-" + DateTime.Now.ToString()); //Console.WriteLine("hello1"); try { //GlobalMethod.log.Info("爬虫运行:"+DateTime.Now.ToString()); var result = EnterRepository.GetRepositoryEnter().BlogRepository.LoadEntities().OrderByDescending(m => m.ModifyTime).Take(10).ToList(); foreach (var item in result) { SpiderServices.SpiderRelationPage(item.ReprintUrl); } //GlobalMethod.log.Info("爬虫运行,抓取今日头条" + DateTime.Now.ToString()); var result2 = EnterRepository.GetRepositoryEnter().ToutiaoRepository.LoadEntities().OrderByDescending(m => m.ModifyTime).Take(10).ToList(); foreach (var item in result) { SpiderServices.SpiderRelationPageToutiao(item.ReprintUrl); } } catch (Exception ex) { GlobalMethod.log.Error(ex); } }
public ActionResult SpiderRelation() { string writeMsg = "抓取成功!"; try { string strurls = Request.Form["cbx_select"] != "" ? Request.Form["cbx_select"] : ""; if (strurls != string.Empty) { string[] urls = strurls.Split(','); foreach (var item in urls) { if (string.IsNullOrEmpty(item)) { continue; } bool result = SpiderServices.SpiderRelationPage(item); if (!result) { writeMsg = "抓取失败"; break; } } } return(Content(writeMsg)); } catch (Exception ex) { GlobalMethod.log.Error(ex); writeMsg = "抓取失败"; return(Content(writeMsg)); } }
/// <summary> /// 浏览相关文章 /// </summary> /// <param name="id"></param> /// <returns></returns> public ActionResult ViewRelation() { string url = Request.QueryString["url"]; if (!string.IsNullOrEmpty(url)) { SpiderServices.SpiderRelationPage(url); } return(RedirectToAction("index")); }