Esempio n. 1
0
        //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);
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
      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);
      }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
        //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);
        }