private async Task <List <JobResponseDTO> > GetJobListFromLiepinAsync(string city, string keyword, int pageIndex) { var cityCode = CityCode.GetCityCode(JobSource.猎聘, city); string url = string.Format("http://www.liepin.com/zhaopin/?key={0}&dqs={1}&curPage={2}", keyword, cityCode, pageIndex); using (HttpClient httpClient = new HttpClient()) { var htmlString = await httpClient.GetStringAsync(url); HtmlParser htmlParser = new HtmlParser(); var jobs = (await htmlParser.ParseAsync(htmlString)).QuerySelectorAll("ul.sojob-list li") .Where(a => a.QuerySelectorAll(".job-info h3 a").FirstOrDefault() != null) .Select(b => new JobResponseDTO() { JobTitle = b.QuerySelectorAll(".job-info h3 a").FirstOrDefault().TextContent, CompanyName = b.QuerySelectorAll(".company-name a").FirstOrDefault().TextContent, Salary = b.QuerySelectorAll(".text-warning").FirstOrDefault().TextContent, WorkingPlace = b.QuerySelectorAll(".area").FirstOrDefault().TextContent, ReleaseDate = b.QuerySelectorAll(".time-info time").FirstOrDefault().TextContent, DetailUrl = b.QuerySelectorAll(".job-info h3 a").FirstOrDefault().Attributes.FirstOrDefault(f => f.Name == "href").Value, JobSource = JobSource.猎聘, JobSourceText = "猎聘" }).ToList(); return(jobs); } }
private async Task <List <JobResponseDTO> > GetJobListFromBossAsync(string city, string keyword, int pageIndex) { var cityCode = CityCode.GetCityCode(JobSource.BOSS, city); string url = string.Format("http://www.zhipin.com/c{0}/h_{0}/?query={1}&page={2}", cityCode, keyword, pageIndex); using (var httpClient = new HttpClient()) { var htmlString = await httpClient.GetStringAsync(url); HtmlParser htmlParser = new HtmlParser(); var jobs = (await htmlParser.ParseAsync(htmlString)).QuerySelectorAll(".job-list ul li") .Where(a => a.QuerySelectorAll(".info-primary h3").FirstOrDefault() != null) .Select(b => new JobResponseDTO() { JobTitle = b.QuerySelectorAll(".info-primary h3").FirstOrDefault().TextContent, CompanyName = b.QuerySelectorAll(".company-text h3").FirstOrDefault().TextContent, Salary = b.QuerySelectorAll(".info-primary h3 .red").FirstOrDefault().TextContent, WorkingPlace = b.QuerySelectorAll(".info-primary p").FirstOrDefault().TextContent, ReleaseDate = b.QuerySelectorAll(".job-time .time").FirstOrDefault().TextContent, DetailUrl = "http://www.zhipin.com" + b.QuerySelectorAll("a").FirstOrDefault().Attributes.FirstOrDefault(f => f.Name == "href").Value, JobSource = JobSource.BOSS, JobSourceText = "BOSS直聘" }).ToList(); return(jobs); } }
private async Task <List <JobResponseDTO> > GetJobListFromQianchengAsync(string city, string keyword, int pageIndex) { var cityCode = CityCode.GetCityCode(JobSource.前程, city); string url = string.Format("http://search.51job.com/jobsearch/search_result.php?jobarea={0}&keyword={1}&curr_page={2}", cityCode, keyword, pageIndex); using (HttpClient httpClient = new HttpClient()) { var htmlBytes = await httpClient.GetByteArrayAsync(url); var htmlString = Encoding.GetEncoding("GBK").GetString(htmlBytes); HtmlParser htmlParser = new HtmlParser(); var jobs = (await htmlParser.ParseAsync(htmlString)).QuerySelectorAll(".dw_table div.el") .Where(a => a.QuerySelectorAll(".t1 span a").FirstOrDefault() != null) .Select(b => new JobResponseDTO() { JobTitle = b.QuerySelectorAll(".t1 span a").FirstOrDefault().TextContent, CompanyName = b.QuerySelectorAll(".t2 a").FirstOrDefault().TextContent, WorkingPlace = b.QuerySelectorAll(".t3").FirstOrDefault().TextContent, Salary = b.QuerySelectorAll(".t4").FirstOrDefault().TextContent, ReleaseDate = b.QuerySelectorAll(".t5").FirstOrDefault().TextContent, DetailUrl = b.QuerySelectorAll(".t1 span a").FirstOrDefault().Attributes.FirstOrDefault(f => f.Name == "href").Value, JobSource = JobSource.前程, JobSourceText = "前程无忧" }).ToList(); return(jobs); } }