예제 #1
0
파일: Parser.cs 프로젝트: Team-on/works
        public void Parse(string category, string search, string city)
        {
            parsed.Clear();

            mainUrl = "https://jobs.dou.ua/vacancies/?";
            if (!category?.Equals("") ?? false)
            {
                mainUrl += $"category={category}";
            }
            if (!search?.Equals("") ?? false)
            {
                if (mainUrl.LastChar() != '?')
                {
                    mainUrl += '&';
                }
                mainUrl += $"search={search}";
            }
            if (!city?.Equals("") ?? false)
            {
                if (mainUrl.LastChar() != '?')
                {
                    mainUrl += '&';
                }
                if (city == "удаленная работа")
                {
                    mainUrl += $"remote";
                }
                if (city == "работа за рубежом")
                {
                    mainUrl += $"relocation";
                }
                else
                {
                    sbyte i = (sbyte)city.IndexOf('(');
                    if (i > 0)
                    {
                        city = city.Substring(0, i);
                    }
                    mainUrl += $"city={city}";
                }
            }

            doc = web.Load(mainUrl);

            var vacancyNodes = doc.GetElementbyId("vacancyListId").Descendants("div").Where((a) => a.HasClass("vacancy"));

            Vacancy  vacancy;
            HtmlNode titleNode, aNode;

            foreach (var vacancyDiv in vacancyNodes)
            {
                vacancy = new Vacancy();

                /*
                 * <div class="vacancy" _id="73959">
                 *      <div class="title">
                 *              <a class="vt" href="https://jobs.dou.ua/companies/fiducia-software/vacancies/73959/?from=list_hot">PHP developer (Google partner project)</a>
                 *
                 *              <strong>в
                 *                      <a class="company" href="https://jobs.dou.ua/companies/fiducia-software/vacancies/?from=list_hot">
                 *                              <img>FiduciaSoft
                 *                      </a>
                 *              </strong>
                 *              <span class="salary">$1000–2000</span>
                 *              <span class="cities">Киев</span>
                 *      </div>
                 *
                 *      <div class="sh-info">
                 *              DESCRIPTION
                 *      </div>
                 * </div>
                 */
                try {
                    vacancy.IdDou            = vacancyDiv.GetAttributeValue("_id", 1);
                    vacancy.ShortDescription = vacancyDiv.ChildNodes.FirstOrDefault((a) => a.HasClass("sh-info"))?.InnerText?.Trim()?.ClearFromHTML();

                    titleNode = vacancyDiv.ChildNodes.FirstOrDefault((a) => a.HasClass("title"));
                    aNode     = titleNode.ChildNodes.FindFirst("a");

                    vacancy.Title = aNode.InnerText.ClearFromHTML();
                    vacancy.Link  = aNode.GetAttributeValue("href", null);
                    if (vacancy.Link != null)
                    {
                        short len = (short)(vacancy.Link.IndexOf('?'));
                        if (len > 0)
                        {
                            vacancy.Link = vacancy.Link.Substring(0, len);
                        }
                    }

                    vacancy.Company = titleNode.ChildNodes.FindFirst("strong").ChildNodes.FindFirst("a").InnerText.ClearFromHTML();

                    vacancy.City   = titleNode.ChildNodes.FirstOrDefault((a) => a.HasClass("cities"))?.InnerText?.ClearFromHTML();
                    vacancy.Salary = titleNode.ChildNodes.FirstOrDefault((a) => a.HasClass("salary"))?.InnerText?.ClearFromHTML();

                    vacancy.Date = null;

                    System.Windows.Application.Current.Dispatcher.Invoke(() => {
                        parsed.Add(vacancy);
                        if (VacancyContext.db.Vacancies.FirstOrDefault((a) => a.IdDou == vacancy.IdDou) == null)
                        {
                            VacancyContext.db.Vacancies.Add(vacancy);
                        }
                    });
                }
                catch (Exception ex) {
                    if (System.Windows.MessageBox.Show($"{ex.Message}\n\n{ex.StackTrace}", "Error", System.Windows.MessageBoxButton.OKCancel) == System.Windows.MessageBoxResult.Cancel)
                    {
                        break;
                    }
                }
            }

            System.Windows.Application.Current.Dispatcher.Invoke(() => VacancyContext.db.SaveChanges());
            System.Windows.MessageBox.Show("Done parsing!");
        }
예제 #2
0
 public VacancyInfo(Vacancy vacancy)
 {
     InitializeComponent();
     this.DataContext = vacancy;
 }