/// <summary> /// 获取每页工作内容,保存工作id到redis /// </summary> /// <param name="url"></param> /// <returns></returns> public List <sys_job> Get_Jobs(string url) { try { IHtmlDocument html = new JumonyParser().LoadDocument(url); var jobs = html.Find(".search-result a.job-item"); List <sys_job> retlist = new List <sys_job>(); foreach (var item in jobs) { string joburl = item.Attribute("href").Value(); string full_joburl = domain + item.Attribute("href").Value(); int pos1 = joburl.LastIndexOf("/"); int pos2 = joburl.LastIndexOf("."); string jobidstr = joburl.Substring(pos1 + 1, pos2 - (pos1 + 1)); bool isok = db.SetAdd("jobid", jobidstr); if (!isok) { continue; } var dic = getjobdesc(full_joburl); sys_job sysjob = new sys_job { addtime = DateTime.Now, amount = item.Find(".money").FirstOrDefault().InnerText().Replace("预算:¥", ""), author = dic["zz"], desc = Regex.Replace(dic["desc"], "<.*?>", ""), gq = item.Find(".period").FirstOrDefault().InnerText().Replace("工期:", ""), jobid = jobidstr, joburl = full_joburl, number = dic["number"], rq = item.Find(".publish_at").FirstOrDefault().InnerText().Replace("发布时间:", ""), status = item.Find(".work_status").FirstOrDefault().InnerText(), tag = item.Find(".pattern").FirstOrDefault().InnerText(), title = item.Find(".job-title div").FirstOrDefault().InnerText(), price_min = dic.ContainsKey("price_1") ? dic["price_1"] : "", price_max = dic.ContainsKey("price_2") ? dic["price_2"] : "" }; retlist.Add(sysjob); } return(retlist); } catch (Exception e) { log.Error(e.Message); throw; } }
public List <sys_job> YjsJobs(string url) { try { string regtxt = "<.*?>"; IHtmlDocument html = new JumonyParser().LoadDocument(url); var jobs = html.Find("#db_adapt_id .weui_panel"); List <sys_job> listjob = new List <sys_job>(); foreach (var item in jobs) { string joburl = item.Find("a").FirstOrDefault().Attribute("href").Value(); int pos1 = joburl.LastIndexOf("/"); string jobid = joburl.Substring(pos1 + 1, joburl.Length - (pos1 + 1)); bool isok = this.db.SetAdd("yjsjobid", jobid); if (!isok) { continue; } string jobtitle = item.Find("a .topic_title") != null?item.Find("a .topic_title").FirstOrDefault().InnerText() : ""; string jobdesc = string.Empty; string jobgs = string.Empty; string jobprice = string.Empty; var subitems = item.Find(".job_list_item_div .media_desc_adapt"); string author = item.Find("h4.weui_media_title ") != null?item.Find("h4.weui_media_title ").FirstOrDefault().InnerText() : ""; bool isover = item.ToString().IndexOf("zhushi_span") > 0 ? false : true; if (isover) { continue; } string numberhtml = item.Find("span.zhushi_span") != null?item.Find("span.zhushi_span").FirstOrDefault().InnerHtml() : ""; string number = Regex.Replace(numberhtml, regtxt, ""); foreach (var subitem in subitems) { string subitemhtml = subitem.InnerHtml(); if (subitemhtml.IndexOf("glyphicon-th-large") >= 0) { jobdesc = Regex.Replace(subitemhtml, regtxt, "").Replace("描述:", ""); } if (subitemhtml.IndexOf("glyphicon-hourglass") >= 0) { jobgs = Regex.Replace(subitemhtml, regtxt, "").Replace("工时:", ""); } if (subitemhtml.IndexOf("glyphicon-yen") >= 0) { jobprice = Regex.Replace(subitemhtml, regtxt, "").Replace("总价:", "").Replace("元", ""); } } sys_job jobentry = new sys_job { jobid = jobid, title = jobtitle, desc = jobdesc, number = number, joburl = joburl, addtime = DateTime.Now, amount = jobprice, author = author, gq = jobgs }; listjob.Add(jobentry); } return(listjob); } catch (Exception e) { log.Error(e.Message); throw; } }