Esempio n. 1
0
        private void GetJobInfoFromPage(string pageStr)
        {
            try
            {
                JobInfo info = new JobInfo();
                //--
                if (string.IsNullOrEmpty(pageStr))
                {
                    return;
                }
                //--
                pageStr = pageStr.Replace("\r\n", "");//替换换行符
                // 获取html,body标签内容
                string body = string.Empty;
                string bodyFilter = @"(?is)<body.*?</body>";
                Match m = Regex.Match(pageStr, bodyFilter);
                if (m.Success)
                {
                    body = m.ToString().Replace("<tr >", "<tr>").Replace("\r\n", "");
                }
                // 过滤样式,脚本等不相干标签
                foreach (var filter in Filters)
                {
                    body = Regex.Replace(body, filter[0], filter[1]);
                }
                ////--
                //if (!string.IsNullOrEmpty(mustKey) && !body.Contains(mustKey))
                //{
                //    return;
                //}
                body = Regex.Replace(body, "\\s", "");
                bodyFilter = "(?is)<divclass=\"newlist_list_content\"id=\"newlist_list_content_table\">.*?</dd></dl></div></div></div>";
                Match m1 = Regex.Match(body, bodyFilter);
                if (m1.Success)
                {
                    body = m1.ToString();
                }




                //info.Url = xurl;

                if (GetJobEnd != null)
                {
                    GetJobEnd(pageStr, info);
                }

                //pageStr = Regex.Replace(pageStr, "\\s|&nbsp;|<br>|<strong>|</strong>|<b>|</b>", "");
                ////职位所有信息
                //string jobInfoRegexStr = "(?<=<tableclass=\"search-result-tab\">)[\\S\\s]+?(?=</table>)";
                //Regex jobInfoRegex = new Regex(jobInfoRegexStr);
                //MatchCollection jobInfoMC = jobInfoRegex.Matches(pageStr);
                //foreach (Match m in jobInfoMC)
                //{
                //    if (!string.IsNullOrEmpty(mustKey) && !m.Value.Contains(mustKey))
                //    {
                //        return;
                //    }

                //    JobInfo info = new JobInfo();

                //    //职位名称,url和公司名称
                //    string basicInfoRegexStr = "(?<=<ahref=\")([\\w.:+?()/%=#&]+)\"target=\"_blank\".*?>([\\s\\S]+?)(?=</a>)";
                //    //地点、公司性质、公司规模、经验、学历、职位月薪
                //    string basicInfoRegexStr0 = "(?<=地点:)[-/\\w]+(?=</span>)";
                //    string basicInfoRegexStr1 = "(?<=公司性质:)[-/\\w]+(?=</span>)";
                //    string basicInfoRegexStr2 = "(?<=公司规模:)[-/\\w]+(?=</span>)";
                //    string basicInfoRegexStr3 = "(?<=经验:)[-/\\w]+(?=</span>)";
                //    string basicInfoRegexStr4 = "(?<=学历:)[-/\\w]+(?=</span>)";
                //    string basicInfoRegexStr5 = "(?<=职位月薪:)[-/\\w]+(?=</span>)";
                //    //发布时间
                //    string timeInfoRegexStr = "(?<=releasetime\">)\\d{1,2}-\\d{1,2}-\\d{1,2}";

                //    Regex basicInfoRegex = new Regex(basicInfoRegexStr);
                //    MatchCollection basicInfoMC = basicInfoRegex.Matches(m.Value);
                //    info.Url = basicInfoMC[0].Groups[1].Value;
                //    info.Position = basicInfoMC[0].Groups[2].Value;
                //    info.Company = basicInfoMC[1].Groups[2].Value;
                //    Regex basicInfoRegex0 = new Regex(basicInfoRegexStr0);
                //    info.Address = new Regex(basicInfoRegexStr0).Match(m.Value).Value;
                //    info.Nature = new Regex(basicInfoRegexStr1).Match(m.Value).Value;
                //    info.Scale = new Regex(basicInfoRegexStr2).Match(m.Value).Value;
                //    info.Experience = new Regex(basicInfoRegexStr3).Match(m.Value).Value;
                //    info.Education = new Regex(basicInfoRegexStr4).Match(m.Value).Value;
                //    info.Salary = new Regex(basicInfoRegexStr5).Match(m.Value).Value;
                //    Regex timeInfoRegex = new Regex(timeInfoRegexStr);
                //    info.Time = timeInfoRegex.Match(m.Value).Value;


                //    if (GetJobEnd != null)
                //    {
                //        GetJobEnd(pageStr, info);
                //    }
                //}
            }
            catch (Exception exMsg)
            {
                throw new Exception(exMsg.Message);
            }
        }
Esempio n. 2
0
        private void GetJobInfoFromUrl(string url)
        {
            try
            {
                JobInfo info = new JobInfo();
                //--
                string pageStr = GetHtmlCode.GetByget(url, "gb2312");
                if (string.IsNullOrEmpty(pageStr))
                {
                    return;
                }
                //--
                pageStr = pageStr.Replace("\r\n", "");//替换换行符
                // 获取html,body标签内容
                string body = string.Empty;
                string bodyFilter = @"(?is)<body.*?</body>";
                Match m = Regex.Match(pageStr, bodyFilter);
                if (m.Success)
                {
                    body = m.ToString().Replace("<tr >", "<tr>").Replace("\r\n", "");
                }
                // 过滤样式,脚本等不相干标签
                foreach (var filter in Filters)
                {
                    body = Regex.Replace(body, filter[0], filter[1]);
                }
                //--
                if (!string.IsNullOrEmpty(mustKey) && !body.Contains(mustKey))
                {
                    return;
                }
                body = Regex.Replace(body, "\\s", "");

                info.Url = url;
                string basicInfoRegexStr0 = "<tdclass=\"sr_bt\"colspan=\"2\">(.*?)</td>"; //职位名称
                string position = Regex.Match(body, basicInfoRegexStr0).Value;
                if (string.IsNullOrEmpty(position))
                {
                    basicInfoRegexStr0 = "<tdclass=\"sr_bt\"colspan=\"3\">(.*?)</td>";
                    position = Regex.Match(body, basicInfoRegexStr0).Value;
                }
                info.Position = string.IsNullOrEmpty(position) ? "" : position.Substring(position.IndexOf(">") + 1, position.IndexOf("</") - position.IndexOf(">") - 1);

                string basicInfoRegexStr1 = ".html\">(.*?)</a>";//公司名称 
                string company = Regex.Match(body, basicInfoRegexStr1).Value;
                info.Company = string.IsNullOrEmpty(company) ? "" : company.Substring(company.IndexOf(">") + 1, company.IndexOf("</a>") - company.IndexOf(">") - 1);

                string basicInfoRegexStr2 = "工作地点:</td><tdclass=\"txt_2\">(.*?)</td>";//工作地点
                string address = Regex.Match(body, basicInfoRegexStr2).Value;
                info.Address = string.IsNullOrEmpty(address) ? "" : address.Substring(address.IndexOf("\">") + 2, address.LastIndexOf("</td>") - address.IndexOf("\">") - 2);

                string basicInfoRegexStr3 = "公司性质:</strong>&nbsp;&nbsp;(.*?)<br><br><strong>";//公司性质
                string nature = Regex.Match(body, basicInfoRegexStr3).Value;
                if (string.IsNullOrEmpty(nature))
                {
                    basicInfoRegexStr3 = "公司行业:</strong>&nbsp;&nbsp;(.*?)<br><br><strong>";
                    nature = Regex.Match(body, basicInfoRegexStr3).Value;
                }
                info.Nature = string.IsNullOrEmpty(nature) ? "" : nature.Substring(26, nature.IndexOf("<br>") - 26);//公司性质

                string basicInfoRegexStr4 = "公司规模:</strong>&nbsp;&nbsp;(.*?)</td>";//公司规模
                string scale = Regex.Match(body, basicInfoRegexStr4).Value;
                info.Scale = string.IsNullOrEmpty(scale) ? "" : scale.Substring(26, scale.IndexOf("</td>") - 26);

                string basicInfoRegexStr5 = "工作年限:</td><tdclass=\"txt_2\">(.*?)</td>";//工作经验
                string experience = Regex.Match(body, basicInfoRegexStr5).Value;
                info.Experience = string.IsNullOrEmpty(experience) ? "" : experience.Substring(experience.IndexOf("\">") + 2, experience.LastIndexOf("</td>") - experience.IndexOf("\">") - 2);

                string basicInfoRegexStr6 = "学&nbsp;&nbsp;&nbsp;&nbsp;历:</td><tdclass=\"txt_2\">(.*?)</td>";//学历
                string education = Regex.Match(body, basicInfoRegexStr6).Value;
                info.Education = string.IsNullOrEmpty(education) ? "" : education.Substring(education.IndexOf("\">") + 2, education.LastIndexOf("</td>") - education.IndexOf("\">") - 2);

                string basicInfoRegexStr7 = "薪水范围:</td><tdclass=\"txt_2\">(.*?)</td>";//月薪
                string salary = Regex.Match(body, basicInfoRegexStr7).Value;
                info.Salary = string.IsNullOrEmpty(salary) ? "" : salary.Substring(salary.IndexOf("\">") + 2, salary.LastIndexOf("</td>") - salary.IndexOf("\">") - 2);

                string basicInfoRegexStr8 = "发布日期:</td><tdclass=\"txt_2\">(.*?)</td>";//发布时间
                string time = Regex.Match(body, basicInfoRegexStr8).Value;
                info.Time = string.IsNullOrEmpty(time) ? "" : time.Substring(time.IndexOf("\">") + 2, time.LastIndexOf("</td>") - time.IndexOf("\">") - 2); ;

                if (GetJobEnd != null)
                {
                    GetJobEnd(pageStr, info);
                }
            }
            catch (Exception exMsg)
            {
                throw new Exception(exMsg.Message);
            }
        }
Esempio n. 3
0
        private void GetJobInfoFromUrl(string url)
        {
            try
            {
                JobInfo info = new JobInfo();
                //--
                string pageStr = GetHtmlCode.GetByget(url, "utf-8");
                if (string.IsNullOrEmpty(pageStr))
                {
                    return;
                }
                //--
                pageStr = pageStr.Replace("\r\n", "");//替换换行符
                // 获取html,body标签内容
                string body = string.Empty;
                string bodyFilter = @"(?is)<body.*?</body>";
                Match m = Regex.Match(pageStr, bodyFilter);
                if (m.Success)
                {
                    body = m.ToString().Replace("<tr >", "<tr>").Replace("\r\n", "");
                }
                // 过滤样式,脚本等不相干标签
                foreach (var filter in Filters)
                {
                    body = Regex.Replace(body, filter[0], filter[1]);
                }
                //--
                if (!string.IsNullOrEmpty(mustKey) && !body.Contains(mustKey))
                {
                    return;
                }
                body = Regex.Replace(body, "\\s", "");

                info.Url = url;

                string basicInfoRegexStr0 = "<h1title=([\\s\\S]+?)>(.*?)</h1>"; //职位名称
                string position = Regex.Match(body, basicInfoRegexStr0).Value;
                info.Position = string.IsNullOrEmpty(position) ? "" : position.Substring(position.IndexOf(">") + 1, position.IndexOf("</") - position.IndexOf(">") - 1);//职位名称

                string basicInfoRegexStr1 = "</h1><h3>(.*?)</h3>";//公司名称
                string company = Regex.Match(body, basicInfoRegexStr1).Value;
                info.Company = string.IsNullOrEmpty(company) ? "" : company.Substring(company.IndexOf("<h3>") + 4, company.IndexOf("</h3>") - company.IndexOf("<h3>") - 4);//公司名称

                string basicInfoRegexStr2 = "<divclass=\"resumeclearfix\"><span>(.*?)</span>";//工作地点
                string address = Regex.Match(body, basicInfoRegexStr2).Value;
                info.Address = string.IsNullOrEmpty(address) ? "" : address.Substring(address.IndexOf("<span>") + 6, address.IndexOf("</") - address.IndexOf("<span>") - 6);//工作地点

                string basicInfoRegexStr3 = "<li><span>企业性质:</span>(.*?)</li>";//公司性质
                string nature = Regex.Match(body, basicInfoRegexStr3).Value;
                info.Nature = string.IsNullOrEmpty(nature) ? "" : nature.Substring(nature.IndexOf("</span>") + 7, nature.IndexOf("</li>") - nature.IndexOf("</span>") - 7);//公司性质

                if (string.IsNullOrEmpty(info.Nature))
                {
                    string basicInfoRegexStr3_1 = "<br><span>性质:</span>(.*?)<br>";
                    string nature_1 = Regex.Match(body, basicInfoRegexStr3_1).Value;
                    info.Nature = string.IsNullOrEmpty(nature_1) ? "" : nature_1.Substring(nature_1.IndexOf("</span>") + 7, nature_1.LastIndexOf("<br>") - nature_1.IndexOf("</span>") - 7);//公司性质
                }

                string basicInfoRegexStr4 = "<li><span>企业规模:</span>(.*?)</li>";//公司规模
                string scale = Regex.Match(body, basicInfoRegexStr4).Value;
                info.Scale = string.IsNullOrEmpty(scale) ? "" : scale.Substring(scale.IndexOf("</span>") + 7, scale.IndexOf("</li>") - scale.IndexOf("</span>") - 7);//公司规模

                if (string.IsNullOrEmpty(info.Scale))
                {
                    string basicInfoRegexStr4_1 = "<br><span>规模:</span>(.*?)<br>";
                    string scale_1 = Regex.Match(body, basicInfoRegexStr4_1).Value;
                    info.Scale = info.Nature = string.IsNullOrEmpty(scale_1) ? "" : scale_1.Substring(scale_1.IndexOf("</span>") + 7, scale_1.LastIndexOf("<br>") - scale_1.IndexOf("</span>") - 7);//公司规模
                }

                string basicInfoRegexStr5 = "<spanclass=\"noborder\">(.*?)</span>";//工作经验
                string experience = Regex.Match(body, basicInfoRegexStr5).Value;
                info.Experience = string.IsNullOrEmpty(experience) ? "" : experience.Substring(experience.IndexOf(">") + 1, experience.IndexOf("</") - experience.IndexOf(">") - 1);//工作经验

                string basicInfoRegexStr6 = "</span><span>(.*?)</span><spanclass=\"noborder\">";//最低学历
                string education = Regex.Match(body, basicInfoRegexStr6).Value;
                info.Education = string.IsNullOrEmpty(education) ? "" : education.Substring(education.IndexOf("<span>") + 6, education.IndexOf("</span><spanclass=") - education.IndexOf("<span>") - 6);//最低学历

                string basicInfoRegexStr7 = "<pclass=\"job-main-title\">(.*?)<";//月薪
                string salary = Regex.Match(body, basicInfoRegexStr7).Value;
                info.Salary = string.IsNullOrEmpty(salary) ? "" : salary.Substring(salary.IndexOf(">") + 1, salary.LastIndexOf("<") - salary.IndexOf(">") - 1);//月薪

                string timeInfoRegexStr = "<pclass=\"release-time\">发布时间:<em>(.*?)</em></p>";//发布时间
                string time = Regex.Match(body, timeInfoRegexStr).Value;
                info.Time = string.IsNullOrEmpty(time) ? "" : time.Substring(time.IndexOf("<em>") + 4, time.IndexOf("</em>") - time.IndexOf("<em>") - 4);//发布时间

                if (GetJobEnd != null)
                {
                    GetJobEnd(pageStr, info);
                }
            }
            catch (Exception exMsg)
            {
                throw new Exception(exMsg.Message);
            }
        }