Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Diagnostics;
- using System.Windows.Forms;
- using CefSharp;
- using CefSharp.OffScreen;
- using AngleSharp.Html.Dom;
- using AngleSharp.Html.Parser;
- using AngleSharp.Dom;
- using System.Collections.Generic;
- using System.Text;
- namespace Arbitr
- {
- public partial class Form1 : Form
- {
- ChromiumWebBrowser browser;
- IHtmlDocument angle;
- HtmlParser parser = new HtmlParser();
- string PlaceOfConsiderationSelector = "#chrono_list_content > div > div > div.b-chrono-cols.g-ec > div.r-col > h4 > span:nth-child(2) > span > a";
- string CurrentStep = "#b-case-header > div";
- string CauseSelector = "#b-container > div.b-noColumns-middle.g-fs-120 > dl > dt > span";
- string JudjeNameSelector = "#gr_case_judges > table > tbody > tr > td > div > ul > li";
- string JudjePlaceSelector = "#gr_case_judges > table > thead > tr > td > div > a";
- string DefendantsSelector = "#gr_case_partps > table > tbody > tr > td.defendants > div > ul > li:nth-child(1) > span";
- string ThirdPartiesSelector = "#gr_case_partps > table > tbody > tr > td.third > div > ul > li:nth-child(1) > span > a";
- string OtherPersonsSelector = "#gr_case_partps > table > tbody > tr > td.others > div > ul > li:nth-child(1) > span > a";
- string PlaintiffsSelector = "#gr_case_partps > table > tbody > tr > td.plaintiffs.first > div > ul > li:nth-child(1) > span";
- string hrefForJudjePlace;
- string hrefForPlace;
- public Form1()
- {
- InitializeComponent();
- InitializeChromium();
- browser.FrameLoadEnd += WebBrowserFrameLoadEnded;
- }
- private void WebBrowserFrameLoadEnded(object sender, FrameLoadEndEventArgs e)
- {
- Update();
- }
- public void InitializeChromium()
- {
- CefSettings settings = new CefSettings();
- Cef.Initialize(settings);
- browser = new ChromiumWebBrowser("https://kad.arbitr.ru/");
- //this.Controls.Add(browser);
- //browser.Dock = DockStyle.Fill;
- }
- private void button1_Click(object sender, EventArgs e)
- {
- ClearTextInLabel();
- browser.Load($"https://kad.arbitr.ru/Card?number={textBox1.Text}");
- }
- private new async void Update()
- {
- ClearTextInLabel();
- string html = await browser.GetSourceAsync();
- if (!string.IsNullOrEmpty(html))
- {
- angle = parser.ParseDocument(html);
- if(angle.QuerySelector("#gr_case_partps > table > thead > tr > td.defendants > div") != null)
- {
- if (angle.QuerySelector("#gr_case_partps > table > thead > tr > td.defendants > div").TextContent.Trim() == "Ответчики")
- {
- Debug.WriteLine(angle.QuerySelector("#gr_case_partps > table > thead > tr > td.defendants > div")?.TextContent);
- if (GetElementsBySelector(PlaintiffsSelector) != null)
- {
- Invoke((MethodInvoker)(() =>
- {
- PlaintiffsTop.Text = "Истцы:";
- foreach (IElement element in GetElementsBySelector(PlaintiffsSelector))
- {
- Plaintiffs.Text += element.TextContent.Trim() + "\n\n";
- }
- }));
- }
- if (GetElementsBySelector(DefendantsSelector) != null)
- {
- Invoke((MethodInvoker)(() =>
- {
- StringBuilder stringBuilder = new StringBuilder();
- foreach (IElement element in GetElementsBySelector(DefendantsSelector))
- {
- Defendants.Text += element.TextContent.Trim() + "\n\n";
- }
- DefendantsTop.Text = "Ответчики:";
- }));
- }
- if (GetElementsBySelector(ThirdPartiesSelector) != null)
- {
- Invoke((MethodInvoker)(() =>
- {
- ThirdPartiestTop.Text = "Третьи лица:";
- foreach (IElement element in GetElementsBySelector(ThirdPartiesSelector))
- {
- ThirdParties.Text += element.TextContent.Trim();
- }
- }));
- }
- if (GetElementsBySelector(OtherPersonsSelector) != null)
- {
- Invoke((MethodInvoker)(() =>
- {
- OtherPersonsTop.Text = "Иные лица:";
- foreach (IElement element in GetElementsBySelector(OtherPersonsSelector))
- {
- OtherPersons.Text += element.TextContent.Trim() + "\n\n";
- }
- }));
- }
- if (GetElementBySelector(CurrentStep) != null)
- {
- Invoke((MethodInvoker)(() =>
- {
- ReviewerText.Text = GetElementBySelector(CurrentStep).TextContent.Trim();
- hrefForPlace = GetElementBySelector(CurrentStep).GetAttribute("href");
- }));
- }
- if (GetElementBySelector(PlaceOfConsiderationSelector) != null)
- {
- Invoke((MethodInvoker)(() =>
- {
- Place.Text = GetElementBySelector(PlaceOfConsiderationSelector).TextContent.Trim();
- hrefForPlace = GetElementBySelector(PlaceOfConsiderationSelector).GetAttribute("href");
- }));
- }
- if (GetElementBySelector(JudjeNameSelector) != null)
- {
- Invoke((MethodInvoker)(() =>
- {
- JudjeName.Text = GetElementBySelector(JudjeNameSelector).TextContent.Trim();
- hrefForPlace = GetElementBySelector(JudjeNameSelector).GetAttribute("href");
- }));
- }
- if (GetElementBySelector(CauseSelector) != null)
- {
- Invoke((MethodInvoker)(() =>
- {
- Cause.Text = GetElementBySelector(CauseSelector).TextContent.Trim();
- }));
- }
- if (GetElementBySelector(JudjePlaceSelector) != null)
- {
- Invoke((MethodInvoker)(() =>
- {
- JudjePlace.Text = GetElementBySelector(JudjePlaceSelector).TextContent.Trim();
- hrefForPlace = GetElementBySelector(JudjePlaceSelector).GetAttribute("href");
- }));
- }
- }
- else
- {
- Debug.WriteLine(angle.QuerySelector("#gr_case_partps > table > thead > tr > td.defendants > div")?.TextContent);
- if (GetElementsBySelector(PlaintiffsSelector) != null)
- {
- Invoke((MethodInvoker)(() =>
- {
- foreach (IElement element in GetElementsBySelector(PlaintiffsSelector))
- {
- Plaintiffs.Text += element.TextContent.Trim() + "\n\n";
- }
- PlaintiffsTop.Text = "Кредиторы (заявители):";
- }));
- }
- if (GetElementsBySelector(DefendantsSelector) != null)
- {
- Invoke((MethodInvoker)(() =>
- {
- StringBuilder stringBuilder = new StringBuilder();
- foreach (IElement element in GetElementsBySelector(DefendantsSelector))
- {
- Defendants.Text += element.TextContent.Trim() + "\n\n";
- }
- DefendantsTop.Text = "Должники:";
- }));
- }
- if (GetElementsBySelector(ThirdPartiesSelector) != null)
- {
- Invoke((MethodInvoker)(() =>
- {
- foreach (IElement element in GetElementsBySelector(ThirdPartiesSelector))
- {
- ThirdParties.Text += element.TextContent.Trim();
- }
- ThirdPartiestTop.Text = "Третьи лица:";
- }));
- }
- if (GetElementsBySelector(OtherPersonsSelector) != null)
- {
- Invoke((MethodInvoker)(() =>
- {
- foreach (IElement element in GetElementsBySelector(OtherPersonsSelector))
- {
- OtherPersons.Text += element.TextContent.Trim() + "\n\n";
- }
- OtherPersonsTop.Text = "Иные лица:";
- }));
- }
- if (GetElementBySelector(CurrentStep) != null)
- {
- Invoke((MethodInvoker)(() =>
- {
- ReviewerText.Text = GetElementBySelector(CurrentStep).TextContent.Trim();
- hrefForPlace = GetElementBySelector(CurrentStep).GetAttribute("href");
- }));
- }
- if (GetElementBySelector(PlaceOfConsiderationSelector) != null)
- {
- Invoke((MethodInvoker)(() =>
- {
- Place.Text = GetElementBySelector(PlaceOfConsiderationSelector).TextContent.Trim();
- hrefForPlace = GetElementBySelector(PlaceOfConsiderationSelector).GetAttribute("href");
- }));
- }
- if (GetElementBySelector(JudjeNameSelector) != null)
- {
- Invoke((MethodInvoker)(() =>
- {
- JudjeName.Text = GetElementBySelector(JudjeNameSelector).TextContent.Trim();
- hrefForPlace = GetElementBySelector(JudjeNameSelector).GetAttribute("href");
- }));
- }
- if (GetElementBySelector(CauseSelector) != null)
- {
- Invoke((MethodInvoker)(() =>
- {
- Cause.Text = GetElementBySelector(CauseSelector).TextContent.Trim();
- }));
- }
- if (GetElementBySelector(JudjePlaceSelector) != null)
- {
- Invoke((MethodInvoker)(() =>
- {
- JudjePlace.Text = GetElementBySelector(JudjePlaceSelector).TextContent.Trim();
- hrefForPlace = GetElementBySelector(JudjePlaceSelector).GetAttribute("href");
- }));
- }
- }
- }
- }
- }
- private void ClearTextInLabel()
- {
- Invoke((MethodInvoker)(() =>
- {
- ReviewerText.Text = string.Empty;
- OtherPersons.Text = string.Empty;
- ThirdParties.Text = string.Empty;
- Plaintiffs.Text = string.Empty;
- Defendants.Text = string.Empty;
- JudjePlace.Text = string.Empty;
- JudjeName.Text = string.Empty;
- Place.Text = string.Empty;
- }));
- }
- private List<IElement> GetElementsBySelector(string Selector)
- {
- IElement element = angle.QuerySelector(Selector);
- List<IElement> elements = new List<IElement>();
- int i = 1;
- while(element != null)
- {
- elements.Add(element);
- i++;
- Selector = Selector.Replace((i - 1).ToString(), i.ToString());
- element = angle.QuerySelector(Selector);
- }
- return elements;
- }
- private IElement GetElementBySelector(string Selector)
- {
- IElement element = angle.QuerySelector(Selector);
- if(element != null)
- {
- return element;
- }
- return null;
- }
- private void JudjePlace_Click(object sender, EventArgs e)
- {
- if (!string.IsNullOrEmpty(hrefForJudjePlace))
- {
- Process.Start(hrefForJudjePlace);
- }
- }
- private void Place_Click(object sender, EventArgs e)
- {
- if (!string.IsNullOrEmpty(hrefForPlace))
- {
- Process.Start(hrefForPlace);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement