public List <UngVien> Run(CauHinh ch, List <JobLink> lst_job_link) { is_authenticated = false; List <UngVien> lst_ung_vien = new List <UngVien>(); using (var browser = new XBrowser(user_profile_path, cv_save_path, string.Empty, false, show_browser)) { foreach (var job in lst_job_link) { string url = browser.GoTo(job.link); is_authenticated = url.Contains(ch.url_login) ? browser.Login(ch.url_login, ch.username, ch.password, ch.xpath_username, ch.xpath_password, out string msg) : browser.GetUrl().Contains(url); if (is_authenticated) { string r_url = browser.GoTo(job.link); if (r_url.Contains(job.link)) { var lst_cv_by_job = XuLyCV(browser, job); lst_ung_vien.AddRange(lst_cv_by_job); job.tong_so_cv = lst_cv_by_job.Count; ES.JobLinkRepository.Instance.UpdateTrangThaiXuLy(job); } } } } return(new List <UngVien>(lst_ung_vien)); }
public List <JobLink> ExtractJobLink(CauHinh ch, string link, string app_id, out string msg) { is_authenticated = false; msg = ""; List <JobLink> lst = new List <JobLink>(); using (var browser = new XBrowser(user_profile_path, string.Empty, false, show_browser)) { string url = browser.GoTo(ch.url_login); string wait_xpath = ".//div[@class='kv_login']/div/span"; System.Threading.Thread.Sleep(2000); var home = browser.GetUrl(); if (browser.Find(wait_xpath).Count > 0) { is_authenticated = true; } else { is_authenticated = home == "https://careerbuilder.vn/vi/employers/hrcentral" || (link != url ? browser.Login(ch.url_login, ch.username, ch.password, ch.xpath_username, ch.xpath_password, out msg, wait_xpath, false) : browser.GetUrl().Contains(url)); } if (is_authenticated) { browser.GoTo(link); System.Threading.Thread.Sleep(2000); List <string> lst_links = new List <string>(); var ds_tin = browser.Find( "//div[@id='gird_standard']//dd//span[@class='rc_col_title3 info_jobseeker']/a[1]"); foreach (var tin in ds_tin) { var get_tin = browser.GetAttribute(tin, "href"); var ten_job = tin.Text; if (!string.IsNullOrEmpty(get_tin)) { JobLink job = new JobLink(LoaiLink.JOB_LINK) { app_id = app_id, link = get_tin, trang_thai = TrangThai.DANG_SU_DUNG, trang_thai_xu_ly = TrangThaiXuLy.CHUA_XU_LY, nguoi_tao = ch.username, ten_job = ten_job }; lst.Add(job); } } } } return(lst); }
public List <UngVien> Run(CauHinh ch, List <JobLink> lst_job_link, ToolStripStatusLabel label) { is_authenticated = false; List <UngVien> lst_ung_vien = new List <UngVien>(); string wait_xpath = ".//div[@class='kv_login']/div/span"; using (var browser = new XBrowser(user_profile_path, cv_save_path, string.Empty, false, show_browser)) { if (lst_job_link.Count < 1) { label.Text = "Không có tin nào đang được đăng trực tuyến"; } else { foreach (var job in lst_job_link) { string url = browser.GoTo(job.link); is_authenticated = url.Contains(ch.url_login) ? browser.Login(ch.url_login, ch.username, ch.password, ch.xpath_username, ch.xpath_password, out string msg, wait_xpath, false) : browser.GetUrl().Contains(url); if (is_authenticated) { //string r_url = browser.GoTo(job.link); System.Threading.Thread.Sleep(1000); browser.FindAndClick("//div[@class='top']/ul//div/a"); System.Threading.Thread.Sleep(1000); var lst_url_uv = new List <string>(); var ung_vien = browser.Find(".//form[@id='editFrm1']/dd/span[@class='rc_col_310px info_jobseeker']/div/a"); if (ung_vien.Count > 0) { foreach (var uv in ung_vien) { var url_uv = browser.GetAttribute(uv, "href"); lst_url_uv.Add(url_uv); } } if (lst_url_uv.Count > 0) { foreach (var item in lst_url_uv) { label.Text = $"Đang xử lý link: {job.link}"; browser.GoTo(item); var lst_cv_by_job = XuLyCV(browser, job); lst_ung_vien.AddRange(lst_cv_by_job); } } job.tong_so_cv = lst_url_uv.Count; ES.JobLinkRepository.Instance.UpdateTrangThaiXuLy(job); } } } } return(new List <UngVien>(lst_ung_vien)); }
public void AutoUpdate(CauHinh ch) { var all_saved = ES.LinkSavedRepository.Instance.GetLinksByGiaTri(1, "https://topcv.vn/"); if (all_saved.Count > 0) { using (var browser = new XBrowser()) { string url = browser.GoTo(ch.url_login); var login_form = browser.Find(".//div[@class='panel-body']"); if (login_form.Count > 0) { try { foreach (var element in login_form) { element.FindElement(By.XPath(ch.xpath_username)).SendKeys(ch.username); element.FindElement(By.XPath(ch.xpath_password)).SendKeys(ch.password); element.FindElement(By.XPath(".//button")).Click(); } } catch { } } // top cv status string showing = "https://tuyendung.topcv.vn/tin-tuyen-dung?status=showing"; string waitting = "https://tuyendung.topcv.vn/tin-tuyen-dung?status=waiting"; string not_publish = "https://tuyendung.topcv.vn/tin-tuyen-dung?status=not_publish"; string rejected = "https://tuyendung.topcv.vn/tin-tuyen-dung?status=rejected"; var list_link_status = new List <string> { showing, waitting, not_publish, rejected }; foreach (string link in list_link_status) { browser.GoTo(link); foreach (var tin in all_saved) { var job = tin.ten_job.Remove(tin.ten_job.LastIndexOf(" ", StringComparison.Ordinal)); var find_new = browser.Find($".//a[@class='job-title']/strong[contains(text(),'{job}')]"); if (find_new.Count > 0) { string current_url = browser.GetUrl(); tin.thuoc_tinh = current_url != showing ? current_url != waitting ? current_url == not_publish ? 1 : 4 : 2 : 3; ES.LinkSavedRepository.Instance.UpdateStatus(tin.id, tin.thuoc_tinh); } } } } } }
public List <UngVien> Run(CauHinh ch, List <JobLink> lst_job_link) { is_authenticated = false; List <UngVien> lst_ung_vien = new List <UngVien>(); using (var browser = new XBrowser(user_profile_path, cv_save_path, string.Empty, false, show_browser)) { foreach (var job in lst_job_link) { string url = browser.GoTo(job.link); if (url.Contains(ch.url_login)) { is_authenticated = browser.Login(ch.url_login, ch.username, ch.password, ch.xpath_username, ch.xpath_password, out string msg); } else { is_authenticated = browser.GetUrl().Contains(url); } if (is_authenticated) { string r_url = browser.GoTo(job.link); if (r_url.Contains(job.link)) { var lst_cv_by_job = XuLyCV(browser, job); //Phân trang CV ////ul[@class='pagination']//a var cv_paging_eles = browser.Find("//ul[@class='pagination']//a"); if (cv_paging_eles.Count > 0) { var lst_link_paging = new List <string>(); foreach (var pg_ele in cv_paging_eles) { lst_link_paging.Add(browser.GetAttribute(pg_ele, "href")); } lst_link_paging = lst_link_paging.Distinct().ToList(); foreach (var item in lst_link_paging) { browser.GoTo(item); lst_cv_by_job.AddRange(XuLyCV(browser, job)); ES.JobLinkRepository.Instance.UpdateTrangThaiXuLy(job); } } job.tong_so_cv = lst_cv_by_job.Count; lst_ung_vien.AddRange(lst_cv_by_job); } } } } return(new List <UngVien>(lst_ung_vien)); }
public List <UngVien> Run(CauHinh ch, List <JobLink> lst_job_link, ToolStripStatusLabel toolStripStatusLabel1) { is_authenticated = false; List <UngVien> lst_ung_vien = new List <UngVien>(); string wait_xpath = ".//li[@class='dropdown dropdown-user']"; using (var browser = new XBrowser(user_profile_path, cv_save_path, string.Empty, false, show_browser)) { foreach (var job in lst_job_link) { string url = browser.GoTo(job.link); is_authenticated = url.Contains(ch.url_login) ? browser.Login(ch.url_login, ch.username, ch.password, ch.xpath_username, ch.xpath_password, out string msg, wait_xpath, false) : browser.GetUrl().Contains(url); if (is_authenticated) { //string r_url = browser.GoTo(job.link); System.Threading.Thread.Sleep(1000); browser.FindAndClick(".//a[@href='#tab2']"); var ung_vien = browser.Find(".//tbody[@id='applied']//strong/a"); var url_detail_uv = new List <string>(); foreach (var uv in ung_vien) { var link_uv = browser.GetAttribute(uv, "href"); url_detail_uv.Add(link_uv); } if (url_detail_uv.Count > 0) { foreach (var u_v in url_detail_uv) { browser.GoTo(u_v); toolStripStatusLabel1.Text = $"Đang xử lý link:{job.link}"; var lst_cv_by_job = XuLyCV(browser, job); lst_ung_vien.AddRange(lst_cv_by_job); } } else { job.trang_thai_xu_ly = TrangThaiXuLy.DA_XU_LY; job.ngay_xu_ly = XUtil.TimeInEpoch(); toolStripStatusLabel1.Text = $"Không tìm thấy ứng viên link:{job.link}"; } job.tong_so_cv = url_detail_uv.Count; ES.JobLinkRepository.Instance.UpdateTrangThaiXuLy(job); } } } return(new List <UngVien>(lst_ung_vien)); }
public List <JobLink> ExtractJobLink(CauHinh ch, string link, string app_id, out string msg) { is_authenticated = false; msg = ""; List <JobLink> lst = new List <JobLink>(); using (var browser = new XBrowser(user_profile_path, string.Empty, false, show_browser)) { string url = browser.GoTo(link); string wait_xpath = ".//a[@data-test-key='accountMenuItem']"; is_authenticated = link != url?browser.Login(ch.url_login, ch.username, ch.password, ch.xpath_username, ch.xpath_password, out msg, wait_xpath, false) : browser.GetUrl().Contains(url); if (is_authenticated) { browser.GoTo(link); var eles = browser.Find("//div[@class='Dashboard__dashboard']//a[@class='JobCard__clickable']"); if (eles != null) { foreach (var item in eles) { var url_tin = browser.GetAttribute(item, "href"); var ten_job = item.FindElement(By.XPath(".//strong[@class='BoldedText__regular JobCard__jobTitle']")).Text; if (!string.IsNullOrEmpty(url_tin)) { JobLink job = new JobLink(LoaiLink.JOB_LINK) { app_id = app_id, link = url_tin, trang_thai = TrangThai.DANG_SU_DUNG, trang_thai_xu_ly = TrangThaiXuLy.CHUA_XU_LY, nguoi_tao = ch.username, ten_job = ten_job }; lst.Add(job); } } } } } return(lst); }
public List <JobLink> ExtractJobLink(CauHinh ch, string link, string app_id, out string msg) { is_authenticated = false; msg = ""; List <JobLink> lst = new List <JobLink>(); using (var browser = new XBrowser(user_profile_path, string.Empty, false, show_browser)) { string url = browser.GoTo(link); string wait_xpath = ".//span[@id='currentCredit']"; is_authenticated = url.Contains(ch.url_login) ? browser.Login(ch.url_login, ch.username, ch.password, ch.xpath_username, ch.xpath_password, out msg, wait_xpath, false) : browser.GetUrl().Contains(url); if (is_authenticated) { browser.GoTo(link); var eles = browser.Find("//tbody[@class='tbody-job']//td[3]/a"); if (eles.Count > 0) { foreach (var item in eles) { var url_tin = browser.GetAttribute(item, "href"); if (!string.IsNullOrEmpty(url_tin)) { JobLink job = new JobLink(LoaiLink.JOB_LINK); job.app_id = app_id; job.link = url_tin; job.trang_thai = TrangThai.DANG_SU_DUNG; job.trang_thai_xu_ly = TrangThaiXuLy.CHUA_XU_LY; job.nguoi_tao = ch.username; lst.Add(job); } } } } } return(lst); }
public void AutoUpdate() { var all_saved = ES.LinkSavedRepository.Instance.GetLinksByGiaTri(1, "https://mywork.com.vn/"); if (all_saved.Count > 0) { using (var browser = new XBrowser()) { foreach (var item in all_saved) { browser.GoTo(item.domain); System.Threading.Thread.Sleep(500); var find = browser.Find(".//div[contains(text(),'Tin tuyển dụng này đã được nhà tuyển dụng khóa trước đó.')]"); item.thuoc_tinh = find.Count > 0 ? 2 : 5; ES.LinkSavedRepository.Instance.UpdateStatus(item.id, item.thuoc_tinh); } } } }
public void AutoUpdate() { var all_saved = ES.LinkSavedRepository.Instance.GetLinksByGiaTri(1, "https://jobstreet.vn/"); if (all_saved.Count > 0) { using (var browser = new XBrowser()) { foreach (var item in all_saved) { browser.GoTo(item.domain); System.Threading.Thread.Sleep(500); var find = browser.Find(".//div[contains(text(),'Đang được đăng trực tuyến')]"); item.thuoc_tinh = find.Count > 0 ? 3 : 5; ES.LinkSavedRepository.Instance.UpdateStatus(item.id, item.thuoc_tinh); } } } }
public bool ExtractThongTin(CauHinh ch, string link, string app_id, out string msg, UngVienJobModel.ChiTietTinModel ct, bool is_debug = false) { _logger.Info("START POST TOPCV"); is_authenticated = false; msg = ""; //string username = XUtil.ConfigurationManager.AppSetting["TopCv:username"]; //string password = XUtil.ConfigurationManager.AppSetting["TopCv:password"]; using (var browser = new XBrowser(user_profile_path, string.Empty, false, is_debug)) { browser.GoTo(ch.url_login); var login_form = browser.Find(".//div[@id='page-login']"); if (login_form.Count >= 1) { foreach (var element in login_form) { try { element.FindElement(By.XPath(ch.xpath_username)).SendKeys(ch.username); element.FindElement(By.XPath(ch.xpath_password)).SendKeys(XUtil.DecodeToken(ch.password)); element.FindElement(By.XPath(ch.xpath_password)).SendKeys(Keys.Enter); } catch (Exception) { } } } else { _logger.Error("LOGIN TOPCV FAILED OR WAS LOGIN!"); } browser.GoTo(link); if (browser.GetUrl() == link) { _logger.Info("LOGIN TOPCV SUCCESS"); is_authenticated = true; } //is_authenticated = link != url ? browser.Login(ch.url_login, ch.username, ch.password, ch.xpath_username, ch.xpath_password, out msg) : browser.GetUrl().Contains(url); if (is_authenticated) { var parent = browser.Find(".//div[@class='panel form-job panel-light']"); if (parent != null) { try { foreach (var element in parent) { // chức danh var send_nganh_nghe = element.FindElement(By.Id("jobTitle")); if (send_nganh_nghe != null) { send_nganh_nghe.SendKeys(ct.chuc_danh); _logger.Info($"da send nganh nghe {ct.chuc_danh}"); } else { _logger.Error($"khong tim thay xpath {ct.chuc_danh}"); } System.Threading.Thread.Sleep(1000); var choose_nganh_nghe = element.FindElement(By.XPath("//input[@id='jobTitle']/preceding-sibling::div")); if (choose_nganh_nghe != null) { choose_nganh_nghe.Click(); } var nganh_nghe_topcv = browser.Find(".//input[@placeholder='Chọn ngành nghề']")?.First(); if (nganh_nghe_topcv != null) { nganh_nghe_topcv.Click(); _logger.Info("chon nganh nghe topcv"); foreach (var work in ct.nganh_nghe) { System.Threading.Thread.Sleep(2000); var nganh_nghe = browser.Find($".//ul[@id='select2-categoryIds-results']/li[text()='{work.Trim()}']")?.First(); if (nganh_nghe == null) { browser.FindAndClick(".//input[@placeholder='Chọn ngành nghề']"); System.Threading.Thread.Sleep(2000); browser.Find($".//ul[@id='select2-categoryIds-results']/li[text()='{work}']") ?.First().Click(); _logger.Info($"da chon nganh nghe {work}"); } else { browser.FindAndClick( $".//ul[@id='select2-categoryIds-results']/li[text()='{work}']"); _logger.Info($"da chon nganh nghe {work}"); } } } // địa điểm var dia_diem = element.FindElement(By.XPath(".//input[@placeholder='Chọn địa điểm']")); if (dia_diem != null) { dia_diem.Click(); _logger.Info("chon dia diem topcv"); System.Threading.Thread.Sleep(2000); var choose_dia_chi = browser.Find($".//ul[@id='select2-cityIds-results']/li[text()='{ct.dia_chi}']")?.First(); if (choose_dia_chi != null) { choose_dia_chi.Click(); _logger.Info($"da chon dia chi top cv {ct.dia_chi}"); } else { _logger.Error("khong tim thay xpath dia chi"); } } // số lượng var so_luong = element.FindElement(By.Id("quantity")); if (so_luong != null) { so_luong.SendKeys(ct.so_luong_tuyen.ToString()); _logger.Info($"da send so luong top cv {ct.so_luong_tuyen}"); } else { _logger.Error("khong tim thay xpath so luong"); } // cấp bậc var cap_bac = element.FindElement(By.XPath("//select[@name='position_id']/following::span[@class='select2 select2-container select2-container--bootstrap'][1]")); if (cap_bac != null) { cap_bac.Click(); System.Threading.Thread.Sleep(2000); var choose_cap_bac = browser.Find($".//span[@class='select2-container select2-container--bootstrap select2-container--open']//li[text()='{ct.cap_bac}']")?.First(); if (choose_cap_bac != null) { choose_cap_bac.Click(); _logger.Info($"da chon cap bac {ct.cap_bac}"); } else { _logger.Error("khong tim thay xpath cap bac"); } } // find textbox var textbox = browser.Find(".//div[@class='note-editable panel-body']"); if (textbox.Count > 0) { // mô tả công việc var mo_ta_cong_viec = textbox[0]; if (mo_ta_cong_viec != null) { mo_ta_cong_viec.SendKeys(ct.mo_ta_cong_viec); _logger.Info($"da send mo ta cong viec {ct.mo_ta_cong_viec}"); } else { _logger.Error("khong tim thay xpath mo ta cong viec"); } // yêu cầu ứng viên var yeu_cau_ung_vien = textbox[1]; if (yeu_cau_ung_vien != null) { yeu_cau_ung_vien.SendKeys(ct.yeu_cau_cong_viec); _logger.Info($"da send yeu_cau_cong_viec {ct.yeu_cau_cong_viec}"); } else { _logger.Error("khong tim thay xpath yeu_cau_cong_viec"); } var quyen_loi_ung_vien = textbox[2]; if (quyen_loi_ung_vien != null) { quyen_loi_ung_vien.SendKeys(ct.quyen_loi_ung_vien); _logger.Info($"da send quyen_loi_ung_vien {ct.quyen_loi_ung_vien}"); } else { _logger.Error("khong tim thay xpath quyen_loi_ung_vien"); } } element.FindElement(By.Id("btn-submit")).Click(); System.Threading.Thread.Sleep(1500); var yc_publish = browser.Find(".//div[@id='suggestPublishRequestModal']"); if (yc_publish.Count > 0) { foreach (var item in yc_publish) { item.FindElement(By.XPath(".//button[@class='btn btn-primary']")).Click(); System.Threading.Thread.Sleep(1000); } } System.Threading.Thread.Sleep(1000); string link_post = ""; var find_title_new = browser.Find(".//tbody[@class='tbody-job']/tr[1]"); if (find_title_new.Count > 0) { foreach (var title in find_title_new) { title.FindElement(By.XPath(".//button")).Click(); var els = browser.Find(".//ul/li/a[contains(text(),'Xem CV ứng tuyển')]"); foreach (var e in els) { link_post = browser.GetAttribute(e, "href"); } } } if (!string.IsNullOrEmpty(link_post)) { List <JobLink> lst_saved = new List <JobLink>(); JobLink saved = new JobLink(LoaiLink.JOB_LINK) { ten_job = ct.chuc_danh, app_id = app_id, link = link_post, trang_thai = TrangThai.DANG_SU_DUNG, trang_thai_xu_ly = TrangThaiXuLy.CHUA_XU_LY, nguoi_tao = ch.username }; lst_saved.Add(saved); _logger.Info("POST TOPCV SUCCESS"); return(ES.JobLinkRepository.Instance.IndexMany(lst_saved) > 0); } } } catch (Exception ex) { _logger.Error(ex); } } else { _logger.Error("CAN'T FOUND FORM POST TOPCV"); } } } _logger.Error("POST TOPCV FAILED!"); return(false); }
public bool ExtractThongTin(CauHinh ch, string link, UngVienJobModel.ChiTietTinModel ct, string app_id, out string msg, bool is_debug = false) { msg = ""; is_authenticated = false; using (var browser = new XBrowser(user_profile_path, string.Empty, false, is_debug)) { string url = browser.GoTo(ch.url_login); string wait_xpath = ".//div[@class='kv_login']/div/span"; System.Threading.Thread.Sleep(2000); var home = browser.GetUrl(); if (browser.Find(wait_xpath).Count > 0) { is_authenticated = true; } else { is_authenticated = home == "https://careerbuilder.vn/vi/employers/hrcentral" || (link != url ? browser.Login(ch.url_login, ch.username, ch.password, ch.xpath_username, ch.xpath_password, out msg, wait_xpath, false) : browser.GetUrl().Contains(url)); } browser.GoTo(link); if (is_authenticated) { _logger.Info("LOGIN CAREER BUILDER SUCCESS"); try { var form_post = browser.Find("//div[@id='tab-postjob-description']"); if (form_post.Count > 0) { foreach (var element in form_post) { var chuc_danh = element.FindElement(By.Id("job_title")); if (chuc_danh != null) { chuc_danh.SendKeys(ct.chuc_danh); _logger.Info("da sendkeys chuc danh"); } else { _logger.Error("khong tim thay xpath chuc danh"); } var mo_ta_cv = element.FindElement(By.XPath(".//iframe[@title='Rich Text Editor, job_desc']")); if (mo_ta_cv != null) { mo_ta_cv.SendKeys(ct.mo_ta_cong_viec); _logger.Info("da sendkeys mo ta cong viec"); } else { _logger.Error("khong tim thay xpath mo ta cong viec"); } var yeu_cau_cv = element.FindElement(By.XPath(".//iframe[@title='Rich Text Editor, job_req']")); if (yeu_cau_cv != null) { yeu_cau_cv.SendKeys(ct.yeu_cau_cong_viec); _logger.Info("da sendkeys yeu cau cong viec"); } else { _logger.Error("khong tim thay xpath yeu cau cong viec"); } var nganh_nghe = element.FindElement( By.XPath("//div[@class='fl_left width_202 box_multiSelect_industry']/button")); if (nganh_nghe != null) { nganh_nghe.Click(); foreach (var nn in ct.nganh_nghe) { //browser.FindAndClick($"//li/label/span[text()='{nn}']/preceding-sibling::input"); var find_nn = browser .Find($"//li/label/span[text()='{nn}']/preceding-sibling::input")?.First(); if (find_nn != null) { find_nn.Click(); _logger.Info($"da chon nganh nghe {nn}"); } } } else { _logger.Error("khong tim thay xpath nganh nghe"); } // // địa chỉ var dia_chi = browser .Find( $"//select[@name='LOCATION_ID[]']/optgroup[@label='Việt Nam']/option[text()='{ct.dia_chi}']") ?.First(); if (dia_chi != null) { dia_chi.Click(); _logger.Info($"da chon dia chi {ct.dia_chi}"); } else { _logger.Error("khong tim thay dia chi"); } var btn_add_work = browser.Find("//a[@onclick='addWorkLocation();']")?.First(); if (btn_add_work != null) { btn_add_work.Click(); var ins_dia_chi = browser .Find($"//select[@id='location_id']/option[text()='{ct.dia_chi}']")?.First(); if (ins_dia_chi != null) { ins_dia_chi.Click(); _logger.Info($"da chon dia chi moi la {ct.dia_chi}"); var ins_district = browser .Find($"//select[@id='sldistrict']/option[text()='{ct.district}']") ?.First(); if (ins_district != null) { ins_district.Click(); _logger.Info($"da chon quan {ct.district}"); } else { _logger.Info($"khong tim thay quan {ct.district}"); } } else { _logger.Error($"khong tim thay dia chi {ct.dia_chi}"); } foreach (var address in browser.Find("//input[@id='address']")) { address.SendKeys(ct.dia_chi_chi_tiet); } var save_address = browser.Find("//input[@value='Lưu']")?.First(); if (save_address != null) { save_address.Click(); _logger.Info("da luu dia chi moi tao"); } } else { _logger.Error("khong tim thay button tao dia chi"); } System.Threading.Thread.Sleep(3000); var dia_diem_lam_viec = browser.Find("//input[@value='Địa điểm làm việc']")?.First(); if (dia_diem_lam_viec != null) { dia_diem_lam_viec.Click(); System.Threading.Thread.Sleep(3000); var detail = browser .Find($".//ul[@class='chosen-results']/li[text()='{ct.dia_chi_chi_tiet}']") ?.First(); if (detail != null) { detail.Click(); _logger.Info($"da chon dia chi lam viec: {ct.dia_chi_chi_tiet}"); } else { browser.FindAndClick("//input[@value='Địa điểm làm việc']"); System.Threading.Thread.Sleep(3000); detail.Click(); _logger.Info($"da chon lai dia chi lam viec {ct.dia_chi_chi_tiet}"); } _logger.Info($"da chon dia diem lam viec {ct.dia_chi_chi_tiet}"); } char[] cut_luong = { ',', '/', '-', ' ' }; var arr_luong = ct.muc_luong.Split(cut_luong, StringSplitOptions.RemoveEmptyEntries); var luong_from = arr_luong[0]; var luong_to = arr_luong[1]; var luong_f = element.FindElement(By.Id("salary_from")); if (luong_f != null) { luong_f.SendKeys(luong_from + "000000"); _logger.Info("da sendkeys luong from"); } else { _logger.Error("khong tim thay xpath luong from"); } var luong_t = element.FindElement(By.Id("salary_to")); if (luong_t != null) { luong_t.SendKeys(luong_to + "000000"); _logger.Info("da sendkeys luong to"); } else { _logger.Error("khong tim thay xpath luong from"); } // hình thức làm việc var hinh_thuc_lam_viec = browser .Find( $"//div/label/span[text()='{ct.loai_hinh_cong_viec}']/preceding-sibling::input") ?.First(); if (hinh_thuc_lam_viec != null) { hinh_thuc_lam_viec.Click(); _logger.Info($"da sendkeys hinh thuc lam viec {ct.loai_hinh_cong_viec}"); } else { _logger.Error("khong tim thay xpath hinh thuc lam viec"); } // hạn nhận hồ sơ browser.removeAttrById("JOB_LASTDATE", "readonly"); //element.FindElement(By.Id("JOB_LASTDATE")) // .SendKeys(DateTime.Now.Date.AddMonths(1).ToString("dd/MM/yyyy")); var deadline = element.FindElement(By.Id("JOB_LASTDATE")); if (deadline != null) { deadline.SendKeys(DateTime.Now.Date.AddMonths(1).ToString("dd/MM/yyyy")); _logger.Info("da sendkeys han nhan ho so"); } else { _logger.Info("khong tim thay xpath han nhan ho so"); } // kinh nghiệm JOB_ISEXPERIENCE //browser.FindAndClick( // $"//select[@id='JOB_ISEXPERIENCE']/option[text()='{ct.yeu_cau_kinh_nghiem}']"); var kinh_nghiem = browser .Find($"//select[@id='JOB_ISEXPERIENCE']/option[text()='{ct.yeu_cau_kinh_nghiem}']") ?.First(); if (kinh_nghiem != null) { kinh_nghiem.Click(); _logger.Info($"da chon kinh nghiem {ct.yeu_cau_kinh_nghiem}"); if (ct.yeu_cau_kinh_nghiem == "Có kinh nghiệm") { if (!string.IsNullOrEmpty(ct.kinh_nghiem_from) && !string.IsNullOrEmpty(ct.kinh_nghiem_to)) { var min_year_exp = browser.Find("//input[@id='JOB_FROMEXPERIENCE']"); foreach (var min in min_year_exp) { min.SendKeys(Keys.Control + "a"); min.SendKeys(ct.kinh_nghiem_from); } var max_year_exp = browser.Find("//input[@id='JOB_TOEXPERIENCE']"); foreach (var max in max_year_exp) { max.SendKeys(Keys.Control + "a"); max.SendKeys(ct.kinh_nghiem_to); } } } } else { _logger.Error("khong tim thay xpath kinh nghiem lam viec"); } // cấp bậc làm việc LEVEL_ID var level = browser.Find($"//select[@id='LEVEL_ID']/option[text()='{ct.cap_bac}']") ?.First(); if (level != null) { level.Click(); _logger.Info("da chon cap bac lam viec"); } else { _logger.Error("khong tim thay xpath cap bac lam viec"); } //input[@value='Lưu và Tiếp tục'] browser.FindAndClick("//input[@value='Lưu và Tiếp tục']"); _logger.Info("da luu va tiep tuc buoc 2"); } var save = browser.Find( "//div[@id='tab-postjob-contactinformation']//div[@class='btn_submit']//input")?.First(); if (save != null) { save.Click(); _logger.Info("da click nut submit"); } else { _logger.Error("khong tim thay nut submit"); } System.Threading.Thread.Sleep(3000); var post_job = browser.Find("//div[@id='tab-postjob-matchingscore']//div[@class='btn_submit']//input")?.First(); if (post_job != null) { post_job.Click(); _logger.Info("post job thanh cong"); } System.Threading.Thread.Sleep(3000); var url_tin = browser.GetUrl(); _logger.Info($"lay url job thanh cong: {url_tin}"); List <JobLink> lst_saved = new List <JobLink>(); JobLink saved = new JobLink(LoaiLink.JOB_LINK) { ten_job = ct.chuc_danh, app_id = app_id, link = url_tin, trang_thai = TrangThai.DANG_SU_DUNG, trang_thai_xu_ly = TrangThaiXuLy.CHUA_XU_LY, nguoi_tao = ch.username }; lst_saved.Add(saved); _logger.Info("post tin careerbuilder thanh cong"); return(ES.JobLinkRepository.Instance.IndexMany(lst_saved) > 0); } } catch (Exception ex) { _logger.Error(ex); } } } return(false); }
//public MyWorkPost() //{ //} public bool ExtractThongTin(CauHinh ch, string link, string app_id, out string msg, UngVienJobModel.ChiTietTinModel ct, bool is_debug = false) { _logger.Info("START POST MYWORK"); is_authenticated = false; msg = ""; //string username = XUtil.ConfigurationManager.AppSetting["MyWork:username"]; //string password = XUtil.ConfigurationManager.AppSetting["MyWork:password"]; using (var browser = new XBrowser(user_profile_path, string.Empty, false, is_debug)) { browser.GoTo(ch.url_login); var login_form = browser.Find(".//form[@class='form-hook']"); if (login_form.Count > 0) { try { foreach (var element in login_form) { element.FindElement(By.XPath(ch.xpath_username)).SendKeys(ch.username); element.FindElement(By.XPath(ch.xpath_password)).SendKeys(ch.password); //element.FindElement(By.XPath(".//button[@class='el-button full-width el-button--primary']")).Click(); element.FindElement(By.XPath(ch.xpath_password)).SendKeys(Keys.Enter); //wait element nao do xuat hien _logger.Info("LOGIN MYWORK SUCCESS"); Thread.Sleep(4000); } } catch (Exception e) { Console.WriteLine(e); } } browser.GoTo(link); if (browser.GetUrl() == link) { System.Threading.Thread.Sleep(2000); //is_authenticated = link != url ? browser.Login(ch.url_login, ch.username, ch.password, ch.xpath_username, ch.xpath_password, out msg) : browser.GetUrl().Contains(url); is_authenticated = true; _logger.Info("LOGIN MYWORK SUCCESS"); } if (is_authenticated) { //Thông tin công việc try { var thong_tin_cong_viec = browser.Find(".//div[@class='create-cnt-box'][1]"); if (thong_tin_cong_viec != null) { foreach (var element in thong_tin_cong_viec) { var chuc_danh = element.FindElement(By.XPath( ".//input[@name='title']")); if (chuc_danh != null) { chuc_danh.SendKeys(ct.chuc_danh); _logger.Info($"da send chuc danh {ct.chuc_danh}"); } else { _logger.Error("khong tim thay xpath chuc danh"); } // số lượng tuyển var so_luong = element.FindElement(By.XPath(".//input[@name='vacancy_quantity']")); so_luong.SendKeys(Keys.Control + "a"); so_luong.SendKeys(Keys.Delete); so_luong?.SendKeys(ct.so_luong_tuyen.ToString()); var cap_bac = element.FindElement(By.XPath("div[2]/div/div[5]/div/div[2]/div/div/span/span")); if (cap_bac != null) { cap_bac.Click(); _logger.Info($"da send cap bac : {ct.cap_bac}"); System.Threading.Thread.Sleep(2000); string str_vi_tri = ct.cap_bac; char[] spearator0 = { ',', '/', '-', ' ' }; foreach (string s in str_vi_tri.Split(spearator0, StringSplitOptions.None)) { if (!string.IsNullOrWhiteSpace(s)) { var industry = browser.Find($".//div/div[contains(text(),'{s}')]"); if (industry.Count > 0) { foreach (var item in industry) { if (!string.IsNullOrWhiteSpace(item.Text)) { item.Click(); break; } } } } } } // // loại hình công việc var loai_hinh = element.FindElement(By.XPath("div[2]/div/div[6]/div/div[2]/div/div/span/span")); if (loai_hinh != null) { loai_hinh.Click(); System.Threading.Thread.Sleep(1000); var choose_loai_hinh = browser.Find($".//div/div[contains(text(),'{ct.loai_hinh_cong_viec}')]"); if (choose_loai_hinh != null) { foreach (var choose in choose_loai_hinh) { if (!string.IsNullOrWhiteSpace(choose.Text)) { choose.Click(); break; } } _logger.Info($"da chon loai hinh cong viec: {ct.loai_hinh_cong_viec}"); } else { _logger.Error("khong tim thay xpath loai hinh cong viec"); } } // mức lương var muc_luong = element.FindElement(By.XPath("div[2]/div/div[7]/div/div[2]/div/div/span/span")); if (muc_luong != null) { muc_luong.Click(); _logger.Info($"chon muc luong"); System.Threading.Thread.Sleep(1000); var choose_muc_luong = browser.Find($".//div/div[text()='{ct.muc_luong}']")?.First(); if (choose_muc_luong != null) { choose_muc_luong.Click(); _logger.Info($"da chon muc luong {ct.muc_luong}"); } else { _logger.Error("khong tim thay xpath, khong tim thay muc luong phu hop"); } } // địa điểm làm việc var dia_diem = element.FindElement(By.XPath("div[2]/div/div[9]/div/div[2]/div/div/span/span")); if (dia_diem != null) { dia_diem.Click(); System.Threading.Thread.Sleep(1000); var choose_dia_diem = browser.Find($".//div/div[contains(text(),'{ct.dia_chi}')]")?.First(); if (choose_dia_diem != null) { choose_dia_diem.Click(); _logger.Info($"da chon dia diem {ct.dia_chi}"); } else { _logger.Error("khong tim thay xpath dia diem"); } } // ngành nghề var nganh_nghe = element.FindElement(By.XPath("div[2]/div/div[10]/div/div[2]/div/div/span/span")); if (nganh_nghe != null) { nganh_nghe.Click(); _logger.Info("chon nganh nghe phu hop"); System.Threading.Thread.Sleep(1000); foreach (string nghe in ct.nganh_nghe) { var nn = browser.Find($".//div/div[text()='{nghe}']")?.First(); if (nn != null) { nn.Click(); _logger.Info($"da chon nganh nghe {nn}"); } else { _logger.Error($"khong tim thay xpath nganh nghe {nn}]"); } } } // mô tả công việc var mo_ta = element.FindElement(By.XPath(".//textarea[@name='description']")); if (mo_ta != null) { mo_ta.SendKeys(ct.mo_ta_cong_viec); _logger.Info($"da send mo ta cong viec {ct.mo_ta_cong_viec}"); } else { _logger.Error("khong tim thay xpath mo ta cong viec"); } var quyen_loi = element.FindElement(By.XPath(".//textarea[@name='benefit']")); if (quyen_loi != null) { quyen_loi.SendKeys(ct.quyen_loi_ung_vien); _logger.Info($"da send quyen loi ung vien {ct.quyen_loi_ung_vien}"); } else { _logger.Error("khong tim thay xpath quyen_loi_ung_vien"); } } // Yêu cầu công việc var yeu_cau_cong_viec = browser.Find(".//div[@class='create-cnt-box'][2]"); if (yeu_cau_cong_viec != null) { foreach (var element in yeu_cau_cong_viec) { //kinh nghiem lam viec var ele_kn = element.FindElement(By.XPath("div[2]/div/div[1]/div/div[2]/div/div/span/span")); if (ele_kn != null) { ele_kn.Click(); if (!string.IsNullOrEmpty(ct.yeu_cau_kinh_nghiem)) { var choose_kinh_nghiem = browser.Find($".//div/div[contains(text(),'{ct.yeu_cau_kinh_nghiem}')]")?.First(); choose_kinh_nghiem?.Click(); _logger.Info($"da send yeu cau kinh nghiem {ct.yeu_cau_kinh_nghiem}"); } else { browser.ScrollIntoView(ele_kn); browser.SetAttribute(ele_kn, "readonly", ""); ele_kn.SendKeys("Đã có nhiều kinh nghiệm trong nghề"); _logger.Info($"da send yeu cau kinh nghiem {ct.yeu_cau_kinh_nghiem}"); } } // bang cap var ele_bcap = element.FindElement(By.XPath("div[2]/div/div[2]/div/div[2]/div/div/span/span")); if (ele_bcap != null) { ele_bcap.Click(); var choose_bang_cap = browser.Find($".//div/div[contains(text(),'{ct.bang_cap}')]")?.First(); choose_bang_cap?.Click(); _logger.Info($"da send bang cap {ct.bang_cap}"); } // giới tính var ele_gtinh = element.FindElement(By.XPath("div[2]/div/div[3]/div/div[2]/div/div/span/span")); if (ele_gtinh != null) { ele_gtinh.Click(); var choose_gender = browser .Find($".//div/div[contains(text(),'{ct.gioi_tinh}')]")?.First(); choose_gender?.Click(); _logger.Info($"da send gioi tinh {ct.gioi_tinh}"); } // hạn nộp hồ sơ var date_now = DateTime.Today.AddMonths(1).ToString("dd/MM/yyyy"); var han_nop_hs = element.FindElement(By.XPath("div[2]/div/div[4]/div/div[2]/div/div//input")); if (han_nop_hs != null) { han_nop_hs.SendKeys(Keys.Control + "a"); han_nop_hs.SendKeys(Keys.Delete); han_nop_hs.SendKeys(date_now); _logger.Info($"da send han nop ho so {date_now}"); } else { _logger.Error($"khong tim thay xpath han nop ho so"); } // ngon ngu ho so var ngon_ngu_ho_so = element.FindElement(By.XPath("div[2]/div/div[5]/div/div[2]/div/div/span/span")); if (ngon_ngu_ho_so != null) { ngon_ngu_ho_so.Click(); var choose_ngon_ngu = browser.Find($".//div/div[contains(text(),'Tiếng Việt')]")?.First(); choose_ngon_ngu?.Click(); _logger.Info($"da send gioi tinh {ct.gioi_tinh}"); } // yeu cau cong viec var yc = element.FindElement(By.XPath(".//textarea[@name='job_requirement']")); if (yc != null) { yc.SendKeys(ct.yeu_cau_cong_viec); _logger.Info($"da send yeu cau cong viec {ct.yeu_cau_cong_viec}"); } else { _logger.Error("khong tim thay xpath yeu cau cong viec"); } } } //Thông tin liên hệ(Bắt buộc) var thong_tin_lien_he = browser.Find(".//div[@class='create-cnt-box'][3]"); if (thong_tin_lien_he != null) { foreach (var element in thong_tin_lien_he) { // ten nguoi lien he var nguoi_lien_he = element.FindElement(By.XPath(".//input[@name='contact_name']")); if (nguoi_lien_he != null) { //IWebElement textBox = nguoi_lien_he; //textBox.SendKeys(Keys.Control + "a"); nguoi_lien_he.SendKeys(ct.lien_he); _logger.Info($"da send nguoi lien he {ct.lien_he}"); } else { _logger.Error($"khong tim thay xpath lien he"); } // dia chi lien he var dia_chi_lien_he = element.FindElement(By.XPath(".//input[@name='contact_address']")); if (dia_chi_lien_he != null) { //IWebElement textBox = nguoi_lien_he; //textBox.SendKeys(Keys.Control + "a"); dia_chi_lien_he.SendKeys(ct.dia_chi_chi_tiet); _logger.Info($"da send dia_chi lien he {ct.dia_chi_chi_tiet}"); } else { _logger.Error($"khong tim thay xpath lien he"); } //so dien thoai lien he var sdt_lien_he = element.FindElement(By.XPath(".//input[@name='contact_phone']")); if (sdt_lien_he != null) { sdt_lien_he.SendKeys(Keys.Control + "a"); sdt_lien_he.SendKeys(ct.so_dien_thoai); _logger.Info($"da send so dien thoai {ct.so_dien_thoai}"); } else { _logger.Error($"khong tim thay xpath so dien thoai"); } // email lien he var email_lien_he = element.FindElement(By.XPath(".//input[@name='contact_email']")); if (sdt_lien_he != null) { email_lien_he.SendKeys(ct.email); _logger.Error($"da sendkey email"); } else { _logger.Error($"khong tim thay email"); } } } //var dich_vu = // element.FindElement( // By.XPath(".//input[@placeholder='Chọn dịch vụ cho tin đăng']")); //dich_vu?.Click(); browser.FindAndClick(".//button[@class='btn btn-orange-56 ex-upload']"); _logger.Info("POST MYWORK SUCCESS"); Thread.Sleep(5000); string url_home = browser.GetUrl(); if (url_home == "https://mywork.com.vn/nha-tuyen-dung/tao-tin-tuyen-dung-thanh-cong") { browser.FindAndClick(".//a[@class='btn btn-orange-46 w370 w-100-mb font17']"); Thread.Sleep(1000); if (browser.GetUrl() == "https://mywork.com.vn/nha-tuyen-dung/quan-ly-tin-dang?") { var els = browser.Find($".//div[@class='jobslist-01-cont']//a[text()='{ct.chuc_danh}']"); string link_post = ""; foreach (var r_url in els) { link_post = browser.GetAttribute(r_url, "href"); break; } string id = link_post.Replace("https://mywork.com.vn/nha-tuyen-dung/xem-truoc-tin-dang?id=", "").Split('/').First(); if (!string.IsNullOrEmpty(link_post)) { List <JobLink> lst_saved = new List <JobLink>(); JobLink saved = new JobLink(LoaiLink.JOB_LINK) { ten_job = ct.chuc_danh, app_id = app_id, link = $"https://mywork.com.vn/nha-tuyen-dung/ho-so-da-ung-tuyen?job_id={id}", trang_thai = TrangThai.DANG_SU_DUNG, trang_thai_xu_ly = TrangThaiXuLy.CHUA_XU_LY, nguoi_tao = ch.username }; lst_saved.Add(saved); _logger.Info("POST MYWORK SUCCESS!"); return(ES.JobLinkRepository.Instance.IndexMany(lst_saved) > 0); } } } else { _logger.Error("POST MY WORK FAILED! CAN'T GET LINK POST OR JOB NAME IS EXISTED"); return(false); } } //else //{ // _logger.Error("CAN'T FOUND FORM POST MYWORK"); //} } catch (Exception ex) { _logger.Error(ex); } } } _logger.Error("POST MYWORK FAILED!"); return(false); }
public bool ExtractThongTin(CauHinh ch, string link, string app_id, out string msg, UngVienJobModel.ChiTietTinModel ct, bool is_debug = false) { _logger.Info("START POST JOBSTREET"); is_authenticated = false; msg = ""; //string username = XUtil.ConfigurationManager.AppSetting["JobStreet:username"]; //string password = XUtil.ConfigurationManager.AppSetting["JobStreet:password"]; using (var browser = new XBrowser(user_profile_path, string.Empty, false, is_debug)) { browser.GoTo(ch.url_login); var formLogin = browser.Find(".//div[@class='Card__root']"); if (formLogin.Count > 0) { foreach (var form in formLogin) { form.FindElement(By.XPath(ch.xpath_username)).SendKeys(ch.username); form.FindElement(By.XPath(ch.xpath_password)).SendKeys(XMedia.XUtil.DecodeToken(ch.password)); form.FindElement(By.XPath(".//button[@class='Button__primary Button__insideCard Button__extraTopMargin']")).Click(); System.Threading.Thread.Sleep(3000); _logger.Info("LOGIN JOBSTREET SUCCESS"); } } System.Threading.Thread.Sleep(2000); browser.GoTo(link); var check_login = browser.Find("//*[@id='app']/div/nav/div/div/a[4]"); if (check_login.Count >= 1) { is_authenticated = true; _logger.Info("CHECK LOGIN JOBSTREET SUCCESS"); } System.Threading.Thread.Sleep(2000); if (is_authenticated) { _logger.Info("LOGIN JOBSTREET SUCCESS"); var parent = browser.Find(".//div[@class='Card__root']"); if (parent.Count >= 1) { try { _logger.Info("START SENDKEYS"); foreach (var element in parent) { var chuc_danh = element.FindElement(By.Id("jobTitle")); if (chuc_danh != null) { chuc_danh.SendKeys(ct.chuc_danh); _logger.Info($"da send chuc danh {ct.chuc_danh}"); } else { _logger.Error("khong tim thay xpath chuc danh"); } var loai_hinh_cv = element.FindElement(By.Id("jobType")); if (loai_hinh_cv != null) { loai_hinh_cv.SendKeys(ct.loai_hinh_cong_viec); _logger.Info($"da send loai hinh cong viec {ct.loai_hinh_cong_viec}"); } else { _logger.Error("khong tim thay xpath loai hinh cong viec"); } var mo_ta = element.FindElement(By.XPath(".//div[@class='fr-element fr-view']")); if (mo_ta != null) { mo_ta.SendKeys(ct.mo_ta_cong_viec); _logger.Info($"da send mo ta cong viec {ct.mo_ta_cong_viec}"); } else { _logger.Error("khong tim thay xpath mo ta cong viec"); } var save_button = element.FindElement(By.XPath( ".//button[@class='Button__primary Button__insideCard Button__extraTopMargin']")); if (save_button != null) { save_button.Click(); _logger.Info($"luu lai job thanh cong"); _logger.Info("POST JOBSTREET SUCCESS"); } else { _logger.Error("khong the luu lai cong viec"); } System.Threading.Thread.Sleep(3000); string cur_url = browser.GetUrl(); string del_str = cur_url.Substring(cur_url.LastIndexOf("/", StringComparison.Ordinal)); string link_post = cur_url.Replace(del_str, "/details"); List <JobLink> lst_saved = new List <JobLink>(); JobLink job = new JobLink(LoaiLink.JOB_LINK) { ten_job = ct.chuc_danh, app_id = app_id, link = link_post, trang_thai = TrangThai.DANG_SU_DUNG, trang_thai_xu_ly = TrangThaiXuLy.CHUA_XU_LY, nguoi_tao = ch.username }; lst_saved.Add(job); browser.GoTo("https://employer.jobstreet.vn/vn/home"); _logger.Info("POST JOBSTREET SUCCESS!"); return(ES.JobLinkRepository.Instance.IndexMany(lst_saved) > 0); } #region Step2JobStreet //var parent_next = browser.Find(".//div[@class='Card__root']"); //if (parent_next.Count > 0) //{ // try // { // foreach (var element in parent_next) // { // element.FindElement(By.Id("name")).SendKeys(ct.ten_cong_ty); // element.FindElement(By.Id("country")).SendKeys("Việt Nam"); // IWebElement ele = element.FindElement(By.Id("businessAddress")); // ele.SendKeys(ct.dia_chi_chi_tiet); // System.Threading.Thread.Sleep(1000); // IList<IWebElement> elements = (element.FindElements(By.XPath("//ul[@role='listbox']/child::li"))); // foreach (var ele1 in elements) // { // ele1.Click(); // break; // } // Console.WriteLine("2131"); // foreach (var nganh in ct.nganh_nghe) // { // browser.FindAndClick($".//select[@id='industryId']/option[contains(text(),'{nganh}')]"); // } // element.FindElement(By.Id("businessSize")).SendKeys(ct.quy_mo_doanh_nghiep); // string recruiter = "recruiter"; // var select_pos = new SelectElement(element.FindElement(By.Id("role"))); // select_pos.SelectByValue(recruiter); // element.FindElement(By.Id("recruitmentCompanyName")).SendKeys(ct.ten_cong_ty); // List<LinkSaved> lst_saved = new List<LinkSaved>(); // LinkSaved saved = new LinkSaved(); // saved.website = "jobstreet.vn"; // saved.ten_job = ct.chuc_danh; // lst_saved.Add(saved); // Es.IndexLinkPosted(lst_saved); // return true; // } // } // catch (Exception ex) // { // Console.WriteLine(ex); // } //} #endregion Step2JobStreet } catch (Exception ex) { _logger.Error(ex); } } else { _logger.Error("CAN'T FOUND FORM POST JOBSTREET"); } } else { _logger.Error("LOGIN JOBSTREET FAILED!"); } } _logger.Error("POST JOBSTREET FAILED!"); return(false); }
public bool ExtractThongTin(CauHinh ch, string link, UngVienJobModel.ChiTietTinModel ct, string app_id, out string msg, bool is_debug = false) { _logger.Info("START POST JOBSGO"); msg = ""; is_authenticated = false; using (var browser = new XBrowser(user_profile_path, string.Empty, false, is_debug)) { string url = browser.GoTo(ch.url_login); var login_form = browser.Find(".//div[@class='panel panel-body login-form']"); if (browser.Find("//div[@id='modal']//button").Count > 0) { browser.FindAndClick("//div[@id='modal']//button"); } if (login_form.Count > 0) { try { foreach (var element in login_form) { element.FindElement(By.XPath(ch.xpath_username)).SendKeys(ch.username); element.FindElement(By.XPath(ch.xpath_password)).SendKeys(ch.password); element.FindElement(By.XPath(".//button[@class='display-block btn btn-primary btn-ladda btn-ladda-spinner btn-ladda-progress']")).Click(); System.Threading.Thread.Sleep(2000); } } catch (Exception ex) { _logger.Error(ex); } } browser.GoTo(link); is_authenticated = true; if (is_authenticated) { _logger.Info("LOGIN JOBSGO SUCCESS"); try { var tab1 = browser.Find(".//div[@id='tab1']"); if (tab1.Count > 0) { foreach (var tab in tab1) { var chuc_danh = tab.FindElement(By.Id("jobformcreate-job_title")); if (chuc_danh != null) { chuc_danh.SendKeys(ct.chuc_danh); _logger.Info("da send chuc danh"); } else { _logger.Error("khong tim thay xpath chuc danh"); } var mo_ta = tab.FindElement(By.Id("jobformcreate-job_description_ifr")); if (mo_ta != null) { mo_ta.SendKeys(ct.mo_ta_cong_viec); _logger.Info("da send mo ta cong viec"); } else { _logger.Error("khong tim thay xpath mo ta cong viec"); } var yeu_cau = tab.FindElement(By.Id("jobformcreate-job_requirement_ifr")); if (yeu_cau != null) { yeu_cau.SendKeys(ct.yeu_cau_cong_viec); _logger.Info("da send yeu cau cong viec"); } else { _logger.Error("khong tim thay xpath yeu cau cong viec"); } var quyen_loi = tab.FindElement(By.Id("jobformcreate-job_benefit_ifr")); if (quyen_loi != null) { quyen_loi.SendKeys(ct.quyen_loi_ung_vien); _logger.Info("da send quyen loi ung vien"); } else { _logger.Error("khong tim thay xpath quyen loi ung vien"); } var next_tab = tab.FindElement(By.XPath(".//button[@class='btn btn-primary btn-next btn-ladda btn-ladda-spinner btn-ladda-progress']")); if (next_tab != null) { next_tab.Click(); _logger.Info("luu tab 1 de toi tab 2"); } else { _logger.Error("luu tab 1 de toi tab 2"); } System.Threading.Thread.Sleep(2000); } } var tab2 = browser.Find(".//div[@id='tab2']"); if (tab2.Count > 0) { foreach (var tab in tab2) { var detail_address = tab.FindElement(By.XPath(".//input[@placeholder='Nhập địa điểm']")); if (detail_address != null) { detail_address.SendKeys(ct.dia_chi_chi_tiet); _logger.Info("da send dia chi chi tiet"); } else { _logger.Error("khong tim thay xpath dia chi chi tiet"); } System.Threading.Thread.Sleep(3000); try { foreach (var ele in browser.Find(".//div[@class='pac-container pac-logo hdpi']/div")) { ele.Click(); _logger.Info($"chon dia chi {ele}"); break; } } catch (Exception e) { Console.WriteLine(e.Message); } var dia_chi = browser.Find("//table[@id='tableAddRow']/tbody/tr/td[3]/span")?.First(); if (dia_chi != null) { dia_chi.Click(); System.Threading.Thread.Sleep(1500); var ins_dia_chi = browser.Find($"//span[@class='select2-container select2-container--default select2-container--open']//ul/li[text()='{ct.dia_chi}']")?.First(); if (ins_dia_chi != null) { ins_dia_chi.Click(); _logger.Info($"da send dia chi {ct.dia_chi}"); } else { _logger.Error("khong tim thay xpath dia chi"); } System.Threading.Thread.Sleep(1000); } //Ngành nghề System.Threading.Thread.Sleep(1000); //browser.FindAndClick("//div[@class='form-group field-jobformnew-job_category required']/div/span"); var nganh_nghe = browser.Find("//div[contains(@class,'field-jobformnew-job_category')]")?.First(); if (nganh_nghe != null) { nganh_nghe.Click(); _logger.Info("chon it nhat mot nganh nghe"); foreach (var nn in ct.nganh_nghe) { _logger.Info("Tim nganh nghe"); browser.FindAndClick($"//span[@class='select2-container select2-container--default select2-container--open']//ul/li[text()='{nn}']"); _logger.Info($"da chon nganh nghe: {nn}"); System.Threading.Thread.Sleep(1000); //browser.FindAndClick("//div[@class='form-group field-jobformnew-job_category required has-success']/div/span"); } System.Threading.Thread.Sleep(1000); } // Năm kinh nghiệm if (!string.IsNullOrEmpty(ct.kinh_nghiem_from) && !string.IsNullOrEmpty(ct.kinh_nghiem_to)) { var min_year_exp = browser.Find(".//input[@name='JobFormNew[exp_min_require_year]']")?.First(); if (min_year_exp != null) { min_year_exp.SendKeys(Keys.Control + "a"); min_year_exp.SendKeys(ct.kinh_nghiem_from); _logger.Info("da send nam kinh nghiem from"); } else { _logger.Error("khong tim thay xpath nam kinh nghiem from"); } var max_year_exp = browser.Find(".//input[@name='JobFormNew[exp_max_require_year]']")?.First(); if (max_year_exp != null) { max_year_exp.SendKeys(Keys.Control + "a"); max_year_exp.SendKeys(ct.kinh_nghiem_to); _logger.Info("da send nam kinh nghiem to"); } else { _logger.Error("khong tim thay xpath nam kinh nghiem to"); } } else { browser.FindAndClick("//input[@id='checkbox1']"); _logger.Info("cong viec khong yeu cau kinh nghiem"); } // // Mức lương char[] cut_luong = { ',', '/', '-', ' ' }; var arr_luong = ct.muc_luong.Split(cut_luong, StringSplitOptions.RemoveEmptyEntries); var luong_from = arr_luong[0]; var luong_to = arr_luong[1]; System.Threading.Thread.Sleep(1000); var min_salary = browser.Find(".//input[@name='JobFormNew[min_expect_salary]']")?.First(); if (min_salary != null) { min_salary.SendKeys(Keys.Control + "a"); min_salary.SendKeys(luong_from); _logger.Info($"da send luong from {luong_from}"); } else { _logger.Error("khong tim thay xpath luong from"); } System.Threading.Thread.Sleep(1000); var max_salary = browser.Find(".//input[@name='JobFormNew[max_expect_salary]']")?.First(); if (max_salary != null) { max_salary.SendKeys(Keys.Control + "a"); max_salary.SendKeys(luong_to); _logger.Info($"da send luong to {luong_to}"); } else { _logger.Error("khong tim thay xpath luong to"); } // Bằng cấp System.Threading.Thread.Sleep(1000); var bang_cap = browser.Find("//div[contains(@class,'field-jobformnew-degree')]/div/span")?.First(); if (bang_cap != null) { bang_cap.Click(); _logger.Info("da send bang cap"); System.Threading.Thread.Sleep(1000); var choose_bc = browser.Find($"//span[@class='select2-container select2-container--default select2-container--open']//ul/li[text()='{ct.bang_cap}']")?.First(); if (choose_bc != null) { choose_bc.Click(); _logger.Info($"da chon bang cap {ct.bang_cap}"); } else { _logger.Error("khong tim thay xpath bang cap"); } } // loại hình công việc / Tính chất công việc System.Threading.Thread.Sleep(1000); var loai_hinh_cv = browser.Find("//div[contains(@class,'field-jobformnew-job_type')]/div/span")?.First(); if (loai_hinh_cv != null) { loai_hinh_cv.Click(); _logger.Info("chon loai hinh cong viec"); var choose_loai_hinh = browser.Find( $"//span[@class='select2-container select2-container--default select2-container--open']//ul/li[text()='{ct.loai_hinh_cong_viec}']")?.First(); if (choose_loai_hinh != null) { choose_loai_hinh.Click(); _logger.Info($"da chon loai hinh cong viec {ct.loai_hinh_cong_viec}"); } else { _logger.Error("khong tim thay xpath loai hinh cong viec"); } } System.Threading.Thread.Sleep(1000); // Vị trí System.Threading.Thread.Sleep(1000); var vi_tri = browser.Find("//div[contains(@class,'field-jobformnew-job_position_id')]/div/span")?.First(); if (vi_tri != null) { vi_tri.Click(); _logger.Info("chon vi tri cong viec"); System.Threading.Thread.Sleep(1000); var choose_vi_tri = browser.Find($"//span[@class='select2-container select2-container--default select2-container--open']//ul/li[text()='{ct.cap_bac}']")?.First(); if (choose_vi_tri != null) { choose_vi_tri.Click(); _logger.Info($"da chon vi tri {ct.cap_bac}"); } else { _logger.Error($"khong tim thay xpath vi tri"); } } var save = browser.Find("//button[@class='btn btn-primary btn-next btn-ladda btn-ladda-spinner btn-ladda-progress']")?.First(); if (save != null) { save.Click(); _logger.Info("luu lai cong viec thanh cong"); } else { _logger.Error("khong the luu lai cong viec"); } System.Threading.Thread.Sleep(2000); } } browser.GoTo("https://employer.jobsgo.vn/job/inactive"); var url_tin = browser.Find( $".//table[@class='kv-grid-table table table-hover table-bordered table-striped']//tbody/tr/td[2]/strong/a[@title='Xem chi tiết việc làm và các ứng viên'][text()='{ct.chuc_danh} ']")?.First(); string href = browser.GetAttribute(url_tin, "href"); _logger.Info($"da lay link cua tin tuc : {href}"); var lst_saved = new List <JobLink>(); if (!string.IsNullOrEmpty(href)) { JobLink saved = new JobLink(LoaiLink.JOB_LINK) { ten_job = ct.chuc_danh, app_id = app_id, link = href, trang_thai = TrangThai.DANG_SU_DUNG, trang_thai_xu_ly = TrangThaiXuLy.CHUA_XU_LY, nguoi_tao = ch.username }; lst_saved.Add(saved); return(ES.JobLinkRepository.Instance.IndexMany(lst_saved) > 0); } } catch (Exception ex) { Console.WriteLine(ex); } } } return(false); }
public List <JobLink> ExtractJobLink(CauHinh ch, string link, string app_id, out string msg) { is_authenticated = false; msg = ""; List <JobLink> lst = new List <JobLink>(); using (var browser = new XBrowser(user_profile_path, string.Empty, false, show_browser)) { string url = browser.GoTo("https://mywork.com.vn/nha-tuyen-dung/dang-nhap"); string wait_xpath = ".//div[@class='icon_menu user-info text-center']"; System.Threading.Thread.Sleep(2000); var home = browser.GetUrl(); is_authenticated = home == "https://mywork.com.vn/" || (link != url ? browser.Login(ch.url_login, ch.username, ch.password, ch.xpath_username, ch.xpath_password, out msg, wait_xpath, false) : browser.GetUrl().Contains(url)); if (is_authenticated) { browser.GoTo(link); System.Threading.Thread.Sleep(5000); List <string> lst_links = new List <string>(); var cv_paging_eles = browser.Find("//ul[@class='page-01-lst']//a").Where(x => x.Text != "Trang trước" && x.Text != "Trang sau"); if (cv_paging_eles.Count() > 0) { var lst_link_paging = new List <string>(); foreach (var pg_ele in cv_paging_eles) { browser.Click(pg_ele); System.Threading.Thread.Sleep(3000); var e = browser.Find(".//ul[@class='jobslist-01-ul']/li/div/div/ul/li[1]/a"); try { foreach (var item_href in e) { var ten_job = item_href.Text; var url_tin = browser.GetAttribute(item_href, "href"); lst_links.Add(url_tin); if (!string.IsNullOrEmpty(url_tin)) { JobLink job = new JobLink(LoaiLink.JOB_LINK) { app_id = app_id, link = url_tin, trang_thai = TrangThai.DANG_SU_DUNG, trang_thai_xu_ly = TrangThaiXuLy.CHUA_XU_LY, nguoi_tao = ch.username, ten_job = ten_job }; lst.Add(job); } } } catch (Exception ex) { Console.WriteLine(ex.Message); } } } } } return(lst); }
public List <JobLink> ExtractJobLink(CauHinh ch, List <string> lst_link, string app_id, out string msg) { is_authenticated = false; msg = ""; List <JobLink> lst = new List <JobLink>(); string wait_xpath = ".//li[@class='dropdown dropdown-user']"; //ch.username = "******"; //ch.password = "******"; using (var browser = new XBrowser(user_profile_path, string.Empty, false, show_browser)) { foreach (var link in lst_link) { string url = browser.GoTo(link); is_authenticated = link != url?browser.Login(ch.url_login, ch.username, ch.password, ch.xpath_username, ch.xpath_password, out msg, wait_xpath, false) : browser.GetUrl().Contains(url); browser.GoTo(link); try { var find_modal = browser.Find("//div[@id='modal']"); if (find_modal.Count > 0) { foreach (var modal in find_modal) { modal.FindElement(By.ClassName("close"))?.Click(); } } } catch (Exception e) { Console.WriteLine(e.Message); } if (is_authenticated) { var check_paging = browser.Find(".//ul[@class='pagination']/li/a"); if (check_paging.Count() > 0) { var list_url_page = new List <string>(); foreach (var loop in check_paging) { var url_page = browser.GetAttribute(loop, "href"); list_url_page.Add(url_page); } list_url_page = list_url_page.Distinct().ToList(); foreach (var go_url in list_url_page) { browser.GoTo(go_url); System.Threading.Thread.Sleep(1500); var eles_paging = browser.Find(".//table[@class='kv-grid-table table table-hover table-bordered table-striped']//tbody/tr/td[2]/strong/a[@title='Xem chi tiết việc làm và các ứng viên']"); if (eles_paging.Count > 0) { foreach (var item in eles_paging) { var url_tin = browser.GetAttribute(item, "href"); var ten_job = item.Text; if (!string.IsNullOrEmpty(url_tin)) { var job = new JobLink(LoaiLink.JOB_LINK) { app_id = app_id, link = url_tin, trang_thai = TrangThai.DANG_SU_DUNG, trang_thai_xu_ly = TrangThaiXuLy.CHUA_XU_LY, nguoi_tao = ch.username, ten_job = ten_job }; lst.Add(job); } } } } } else { var eles = browser.Find(".//table[@class='kv-grid-table table table-hover table-bordered table-striped']//tbody/tr/td[2]/strong/a[@title='Xem chi tiết việc làm và các ứng viên']"); if (eles.Count > 0) { foreach (var item in eles) { var url_tin = browser.GetAttribute(item, "href"); var ten_job = item.Text; if (!string.IsNullOrEmpty(url_tin)) { JobLink job = new JobLink(LoaiLink.JOB_LINK) { app_id = app_id, link = url_tin, trang_thai = TrangThai.DANG_SU_DUNG, trang_thai_xu_ly = TrangThaiXuLy.CHUA_XU_LY, nguoi_tao = ch.username, ten_job = ten_job }; lst.Add(job); } } } } } } } return(lst); }
private List <UngVien> XuLyCV(XBrowser browser, JobLink job) { job.trang_thai_xu_ly = TrangThaiXuLy.DA_XU_LY; List <UngVien> lst_ung_vien = new List <UngVien>(); try { var eles_ung_vien = browser.Find("//div[@class='col-sm-9']//form//div[@class='list-group-item-heading']"); if (eles_ung_vien.Count > 0) { Dictionary <string, string> dic_cv_ung_vien = new Dictionary <string, string>(); foreach (var item_ung_vien in eles_ung_vien) { try { var ho_ten_ele = browser.FindChildElement(item_ung_vien, ".//span[@class='text-accent']"); var link_cv_ele = browser.FindChildElement(item_ung_vien, ".//a"); if (ho_ten_ele != null && link_cv_ele != null) { string href = browser.GetAttribute(link_cv_ele, "href").Trim(); string ho_ten = browser.GetAttribute(ho_ten_ele, "innerText").Trim(); if (!dic_cv_ung_vien.ContainsKey(href)) { dic_cv_ung_vien.Add(href, ho_ten); } } } catch (Exception) { } } foreach (var item in dic_cv_ung_vien) { browser.GoTo(item.Key); UngVien ung_vien = new UngVien(); ung_vien.ngay_tao = ung_vien.ngay_sua = XMedia.XUtil.TimeInEpoch(); ung_vien.app_id = job.app_id; ung_vien.job_link = job.link; ung_vien.ho_ten = item.Value; ung_vien.full_text = browser.GetPageSource(); ung_vien.vi_tri = job.ten_job; ThongTinChungUngVien ttuv = new ThongTinChungUngVien(); ttuv.domain = UrlToDomain(item.Key); ttuv.full_text = browser.GetInnerHtml("//div[@class='resume-show']//div[@class='media']", 200); ttuv.full_text += browser.GetInnerHtml("//div[@id='divResumeContactInformation']", 200); ung_vien.thong_tin_chung = ttuv; //Bóc tách XPATH để lấy được thông tin này nếu có ung_vien.kinh_nghiem = browser.GetInnerHtml("//h4[contains(text(),'Kinh nghiệm')]/following-sibling::dl", 200); ung_vien.ky_nang = ""; ung_vien.hoc_van = browser.GetInnerHtml("//h4[contains(text(),'Học vấn')]/following-sibling::dl", 200); ung_vien.email = browser.GetInnerHtml("//a[contains(@href,'mailto')]", 200); ung_vien.so_dien_thoai = browser.GetInnerHtml("//div[@id='divResumeContactInformation']//dt[contains(text(),'Điện')]/following-sibling::dd[1]", 200); string ngay_sinh = browser.GetInnerText("//span[@class='confidential-birth-day']", 500); ung_vien.domain = UrlToDomain(item.Key); ung_vien.custom_id = item.Key.Substring(item.Key.LastIndexOf("/") + 1); ung_vien.nguoi_tao = job.nguoi_tao; if (!string.IsNullOrEmpty(ngay_sinh)) { //Convert ngay sinh System.Globalization.DateTimeFormatInfo dtfi = new System.Globalization.DateTimeFormatInfo(); dtfi.ShortDatePattern = "dd/MM/yyyy"; dtfi.DateSeparator = "/"; try { var bird_day = Convert.ToDateTime(ngay_sinh, dtfi); ung_vien.ngay_sinh = XMedia.XUtil.TimeInEpoch(bird_day); } catch (Exception) { } } var ifr = browser.FindFirst("//iframe"); if (ifr != null) { ung_vien.link_cv_offline = browser.DownloadByBrowserInIFrame("//iframe", "//button[@id='download']"); if (!string.IsNullOrEmpty(ung_vien.link_cv_offline)) { ung_vien.cv_byte = File.ReadAllBytes($"{cv_save_path}\\{ung_vien.link_cv_offline}"); } } lst_ung_vien.Add(ung_vien); } } else { job.thong_tin_xu_ly = Common.KHONG_TIM_THAY_UNG_VIEN; } } catch (Exception ex) { job.trang_thai_xu_ly = TrangThaiXuLy.LOI; job.thong_tin_xu_ly = ex.Message; } job.ngay_xu_ly = XMedia.XUtil.TimeInEpoch(); return(lst_ung_vien); }
public List <JobLink> ExtractJobLink(CauHinh ch, string link, string app_id, out string msg) { is_authenticated = false; msg = ""; List <JobLink> lst = new List <JobLink>(); using (var browser = new XBrowser(user_profile_path, string.Empty, false, show_browser)) { string url = browser.GoTo(link); string wait_xpath = ".//a[@class='user-image']"; is_authenticated = url.Contains(ch.url_login) ? browser.Login(ch.url_login, ch.username, ch.password, ch.xpath_username, ch.xpath_password, out msg, wait_xpath, false) : browser.GetUrl().Contains(url); if (is_authenticated) { browser.GoTo(link); var eles_tin_tuyen_dung = browser.Find("//form[@id='employer-job-manage']//a[contains(@href,'thu-xin-viec-da-nhan')]"); if (eles_tin_tuyen_dung != null) { foreach (var item in eles_tin_tuyen_dung) { var ten_job = item.FindElement(By.XPath(".//parent::div/parent::div/parent::div/parent::div/following-sibling::div/ul[@class='fa-ul']//li[1]")).Text; var url_tin = browser.GetAttribute(item, "href"); if (!string.IsNullOrEmpty(url_tin)) { JobLink job = new JobLink(LoaiLink.JOB_LINK) { app_id = app_id, link = url_tin, trang_thai = TrangThai.DANG_SU_DUNG, trang_thai_xu_ly = TrangThaiXuLy.CHUA_XU_LY, nguoi_tao = ch.username, ten_job = ten_job }; lst.Add(job); } } } var ele_paging = browser.Find("//ul[@class='pagination']//a"); if (ele_paging != null) { var lst_url_paging = new List <string>(); foreach (var ele in ele_paging) { lst_url_paging.Add(browser.GetAttribute(ele, "href")); } lst_url_paging = lst_url_paging.Distinct().ToList(); foreach (var lnk_paging in lst_url_paging) { browser.GoTo(lnk_paging); eles_tin_tuyen_dung = browser.Find("//form[@id='employer-job-manage']//a[contains(@href,'thu-xin-viec-da-nhan')]"); if (eles_tin_tuyen_dung != null) { foreach (var item in eles_tin_tuyen_dung) { var ten_job = item.FindElement(By.XPath("//parent::div/parent::div/parent::div/parent::div/following-sibling::div/ul[@class='fa-ul']//li[1]")).Text; var url_tin = browser.GetAttribute(item, "href"); if (!string.IsNullOrEmpty(url_tin)) { JobLink job = new JobLink(LoaiLink.JOB_LINK); job.app_id = app_id; job.link = url_tin; job.trang_thai = TrangThai.DANG_SU_DUNG; job.trang_thai_xu_ly = TrangThaiXuLy.CHUA_XU_LY; job.nguoi_tao = XMedia.XUtil.DecodeToken(ch.username); job.ten_job = ten_job; lst.Add(job); } } } } } } } lst = lst.GroupBy(x => x.link).Select(s => s.First()).ToList(); return(lst); }
public List <UngVien> Run(CauHinh ch, List <JobLink> lst_job_link) { is_authenticated = false; List <UngVien> lst_ung_vien = new List <UngVien>(); using (var browser = new XBrowser(user_profile_path, cv_save_path, string.Empty, false, show_browser)) { foreach (var job in lst_job_link) { string url = browser.GoTo(job.link); string wait_xpath = ".//div[@class='icon_menu user-info text-center']"; if (url.Contains(ch.url_login) || browser.GetUrl() == "https://mywork.com.vn/") { is_authenticated = browser.Login(ch.url_login, ch.username, ch.password, ch.xpath_username, ch.xpath_password, out string msg, wait_xpath, true); } else { is_authenticated = browser.GetUrl().Contains(url); } if (is_authenticated) { string r_url = browser.GoTo(job.link); System.Threading.Thread.Sleep(3000); if (r_url.Contains(job.link)) { int sleep = 30000; var find_ung_vien = browser.Find(".//div/span[text()='Không có dữ liệu']"); if (find_ung_vien.Count < 1) { while (sleep > 0) { sleep -= 500; System.Threading.Thread.Sleep(500); List <string> lst_cv_ung_vien = new List <string>(); var lst_cv_by_job = new List <UngVien>(); var lst_new = browser.Find("//table[@class='el-table__body']//tbody//div/div/div[1]/a"); if (lst_new.Count < 1) { job.thong_tin_xu_ly = Common.KHONG_TIM_THAY_UNG_VIEN; } var element = browser.Find("//ul[@class='pagination']//a"); if (element.Count > 0) { var cv_paging_eles = element.Where(x => x.Text != null && x.Text != "Trang trước" && x.Text != "Trang sau"); if (cv_paging_eles.Count() > 0) { var all_links_in_page = new List <string>(); var links_process = new List <string>(); foreach (var pg_ele in cv_paging_eles) { browser.Click(pg_ele); System.Threading.Thread.Sleep(2000); lst_new = browser.Find("//table[@class='el-table__body']//tbody//div/div/div[1]/a"); foreach (var lst_ung_vien_new in lst_new) { var url_ung_vien = browser.GetAttribute(lst_ung_vien_new, "href"); links_process.Add(url_ung_vien); } } foreach (var item in links_process) { browser.GoTo(item); System.Threading.Thread.Sleep(3000); lst_cv_by_job.AddRange(XuLyCV(browser, job, item)); } } } else { var current_href = new List <string>(); foreach (var item in lst_new) { var url_ung_vien = browser.GetAttribute(item, "href"); current_href.Add(url_ung_vien); } foreach (var items in current_href) { browser.GoTo(items); lst_cv_by_job.AddRange(XuLyCV(browser, job, items)); job.tong_so_cv = lst_cv_by_job.Count; } } if (lst_new != null && lst_new.Count > 0) { sleep = 0; } job.tong_so_cv = lst_cv_by_job.Count; job.ngay_xu_ly = XMedia.XUtil.TimeInEpoch(); job.trang_thai_xu_ly = TrangThaiXuLy.DA_XU_LY; lst_ung_vien.AddRange(lst_cv_by_job); ES.JobLinkRepository.Instance.UpdateTrangThaiXuLy(job); } } } } } } return(new List <UngVien>(lst_ung_vien)); }
//public CareerLinkPost(string _user_profile_path) //{ // user_profile_path = _user_profile_path; //} public bool ExtractThongTin(CauHinh ch, string link, string app_id, UngVienJobModel.ChiTietTinModel ct, out string msg, bool is_debug = false) { _logger.Info("START POST CAREER LINK"); msg = ""; is_authenticated = false; //string username = XUtil.ConfigurationManager.AppSetting["CareerLink:username"]; //string password = XUtil.ConfigurationManager.AppSetting["CareerLink:password"]; using (var browser = new XBrowser(user_profile_path, string.Empty, false, is_debug)) { string url = browser.GoTo(ch.url_login); var login_form = browser.Find(".//form[@id='login-check-form']"); if (login_form.Count >= 1) { try { foreach (var element in login_form) { element.FindElement(By.XPath(ch.xpath_username)).SendKeys(ch.username); element.FindElement(By.XPath(ch.xpath_password)).SendKeys(XUtil.DecodeToken(ch.password)); element.FindElement(By.XPath(".//input[@name='btnCompanyLogin']")).Click(); _logger.Info("LOGIN CAREER LINK SUCCESS"); } } catch (Exception exception) { Console.WriteLine(exception.Message); } } else { _logger.Info("THIS SITE WAS LOGIN OR NOT FOUND"); } browser.GoTo(link); is_authenticated = true; if (is_authenticated) { _logger.Info("LOGIN CAREER LINKS SUCCESS"); try { _logger.Info("START POST STEP 1"); // step 1 var job_step_1 = browser.Find(".//form[@id='job-step1-form']"); if (job_step_1.Count > 0) { foreach (var step_1 in job_step_1) { var chuc_danh = step_1.FindElement(By.Id("jobStep1_name")); if (chuc_danh != null) { chuc_danh.SendKeys(ct.chuc_danh); _logger.Info("da sendkeys chuc danh"); } else { _logger.Error("khong tim thay xpath chuc danh"); } var next_step = step_1.FindElement(By.XPath(".//input[@value='Lưu Bước 1 để tiếp tục Bước 2']")); if (next_step != null) { next_step.Click(); _logger.Info("luu thanh cong buoc 1 de sang buoc 2"); } else { _logger.Error("khong sang dc buoc 2"); } } } _logger.Info("START POST STEP 2"); // Step 2 var job_step_2 = browser.Find(".//form[@id='job-step2']"); if (job_step_2.Count > 0) { foreach (var step_2 in job_step_2) { // mô tả công việc if (ct.nganh_nghe.Count >= 1) { int count = 1; foreach (string item in ct.nganh_nghe) { var nganh_nghe = browser.Find($".//select[@id='jobStep2_category{count}']/option[contains(text(),'{item}')]")?.First(); if (nganh_nghe != null) { nganh_nghe.Click(); _logger.Info($"da chon nganh nghe {item}"); } count++; } } var tinh_thanh_exac = browser.Find($".//select[@id='jobStep2_province1']/option[contains(text(),'{ct.dia_chi}')]")?.First(); if (tinh_thanh_exac != null) { tinh_thanh_exac.Click(); _logger.Info($"da chon tinh thanh {ct.dia_chi}"); } else { string str = ct.dia_chi; char[] spearator = { ',', '/', '-', ' ' }; string[] strlist = str.Split(spearator, StringSplitOptions.None); foreach (string s in strlist) { if (!string.IsNullOrWhiteSpace(s)) { var industry = browser.Find($".//select[@id='jobStep2_province1']/option[contains(text(),'{s}')]"); if (industry.Count > 0) { foreach (var item in industry) { item.Click(); _logger.Info($"da chon nganh nghe {item}"); break; } } else { browser.FindAndClick(".//select[@id='jobStep2_province1']/option[contains(text(),'Khác')]"); } } } } var loai_hinh = step_2.FindElement(By.Id("jobStep2_positionType")); if (loai_hinh != null) { loai_hinh.SendKeys(ct.loai_hinh_cong_viec); _logger.Info("da send loai hinh cong viec"); } //step_2.FindElement(By.Id("jobStep2_desireCareerLevel")); var cap_bac = browser.Find($".//select[@id='jobStep2_desireCareerLevel']/option[text()='{ct.cap_bac}']")?.First(); if (cap_bac != null) { cap_bac.Click(); _logger.Info($"da tim thay cap bac {ct.cap_bac}"); } else { string str_vi_tri = ct.cap_bac; char[] spearator0 = { ',', '/', '-', ' ' }; string[] strlist1 = str_vi_tri.Split(spearator0, StringSplitOptions.None); foreach (string s in strlist1) { if (!string.IsNullOrWhiteSpace(s)) { var industry = browser.Find($".//select[@id='jobStep2_desireCareerLevel']/option[contains(text(),'{s}')]"); if (industry.Count > 0) { foreach (var item in industry) { if (!string.IsNullOrWhiteSpace(item.Text)) { item.Click(); } } } else { browser.FindAndClick(".//ul[@class='el-scrollbar__view el-select-dropdown__list']//span[contains(text(),'Ngành nghề khác')]/ancestor::li"); } } } } //step_2.FindElement(By.Id()); var luong = ct.muc_luong; char[] cut_luong = { ',', '/', '-', ' ' }; var arr_luong = luong.Split(cut_luong, StringSplitOptions.RemoveEmptyEntries); var luong_from = arr_luong[0]; var luong_to = arr_luong[1]; var luong_f = step_2.FindElement(By.Id("jobStep2_salaryFrom")); if (luong_f != null) { luong_f.SendKeys($"{luong_from}000000"); _logger.Info("da send luong from"); } var luong_t = step_2.FindElement(By.Id("jobStep2_salaryTo")); if (luong_t != null) { luong_t.SendKeys($"{luong_to}000000"); _logger.Info("da send luong from"); } var mo_ta_cong_viec = step_2.FindElement(By.Id("jobStep2_description_ifr")); if (mo_ta_cong_viec != null) { mo_ta_cong_viec.SendKeys(ct.mo_ta_cong_viec); _logger.Info("da send mo ta cong viec"); } else { _logger.Error("khong tim thay xpath mo ta cong viec"); } // Kinh nghiệm / kỹ năng browser.FindAndClick(".//select[@id='jobStep2_educationLevel']/option[contains(text(),'Khác')]"); var kinh_nghiem = step_2.FindElement(By.Id("jobStep2_experienceLevel")); if (kinh_nghiem != null) { kinh_nghiem.SendKeys("1-2 năm kinh nghiệm"); _logger.Info("da send kinh nghiem lam viec"); } else { _logger.Error("khong tim thay xpath kinh nghiem lam viec"); } var yeucau_cv = step_2.FindElement(By.Id("jobStep2_skill_ifr")); if (yeucau_cv != null) { yeucau_cv.SendKeys(ct.yeu_cau_cong_viec); _logger.Info("da send yeu cau cong viec"); } else { _logger.Error("khong tim thay xpath yeu cau cong viec"); } //step_2.FindElement(By.XPath(".//input[@value='Lưu Bước 2 để tiếp tục Bước 3']")).Click(); var step2to3 = step_2.FindElement(By.XPath(".//input[@value='Lưu Bước 2 để tiếp tục Bước 3']")); if (step2to3 != null) { step2to3.Click(); _logger.Info("da click buoc 2 de toi buoc 3"); } else { _logger.Error("khong den duoc step 3"); } System.Threading.Thread.Sleep(2000); } } _logger.Info("START POST STEP 3"); // Step 3 Thông tin liên hệ var job_step_3 = browser.Find(".//form[@id='job-step3']"); if (job_step_3.Count > 0) { foreach (var step3 in job_step_3) { //step3.FindElement(By.Id("jobStep3_applicationPreferredLanguage")).SendKeys("Tiếng Việt"); var ngon_ngu = step3.FindElement(By.Id("jobStep3_applicationPreferredLanguage")); if (ngon_ngu != null) { ngon_ngu.SendKeys("Tiếng Việt"); _logger.Info("da send ngon ngu TiengViet"); } var mo_ta = step3.FindElement(By.Id("jobStep3_contactDescription_ifr")); if (mo_ta != null) { mo_ta.SendKeys(ct.mo_ta_cong_viec); _logger.Info("da send mo ta cong viec"); } else { _logger.Error("Khong tim thay xpath, ko the sendkeys mo ta cong viec"); } //step3.FindElement(By.XPath(".//input[@value='Lưu Bước 3 để xem lại công việc']")).Click(); var next_step = step3.FindElement(By.XPath(".//input[@value='Lưu Bước 3 để xem lại công việc']")); if (next_step != null) { next_step.Click(); _logger.Info(" da luu buoc 3 va xem lai cong viec"); } else { _logger.Error("khong luu duoc cong viec"); } System.Threading.Thread.Sleep(2000); } } _logger.Info("START POST STEP 4"); // Step 4 xem lại và đăng lên string cur_url = browser.GetUrl(); string del_str = cur_url.Substring(cur_url.LastIndexOf("/")); string link_post = cur_url.Replace(del_str, "/"); List <JobLink> lst_saved = new List <JobLink>(); JobLink saved = new JobLink(LoaiLink.JOB_LINK) { ten_job = ct.chuc_danh, app_id = app_id, link = link_post + "thu-xin-viec-da-nhan?status=all", trang_thai = TrangThai.DANG_SU_DUNG, trang_thai_xu_ly = TrangThaiXuLy.CHUA_XU_LY, nguoi_tao = ch.username }; _logger.Info($"da luu link job: {saved.link}"); lst_saved.Add(saved); browser.FindAndClick(".//form/input[@name='btnSubmit']"); _logger.Info("SUCCESS POST CAREER LINK"); return(ES.JobLinkRepository.Instance.IndexMany(lst_saved) > 0); } catch (Exception ex) { _logger.Error(ex); } } } _logger.Error("POST CAREER LINK FAILED!"); return(false); }