using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using CefSharp;
using CefSharp.WinForms;
using HtmlAgilityPack;
namespace MouArBiTp
{
public partial class Form1 : Form
{
ChromiumWebBrowser browser;
HtmlAgilityPack.HtmlDocument html = new HtmlAgilityPack.HtmlDocument();
public Form1()
{
InitializeComponent();
InitializeChromium();
browser.FrameLoadEnd += Browser_FrameLoadEnd;
}
private async void Browser_FrameLoadEnd(object sender, FrameLoadEndEventArgs e)
{
// await Task.Delay(1000);
var source = await browser.EvaluateScriptAsync("document.documentElement.outerHTML");
if(source != null)
{
try
{
html.LoadHtml((string)source.Result);
var node = html.DocumentNode.SelectNodes("//*[@id='b-case-header']/ul[2]/li[4]/a");
if (node != null)
{
Debug.WriteLine(node[0].InnerText);
browser.ExecuteScriptAsync("document.evaluate(\"//*[@id='b-case-header']/ul[2]/li[4]/a\", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.click();");
}
else
{
node = html.DocumentNode.SelectNodes("//*[@id='gr_case_partps']/table/tbody/tr/td[1]/div/ul/li/span/text()");
if (node != null)
{
BeginInvoke(new Action(() => plaintiffs.Text = "Истцы:\n" + node[0].InnerText.Trim()));
node = html.DocumentNode.SelectNodes("//*[@id='gr_case_partps']/table/tbody/tr/td[4]/div/ul/li/span/text()");
if (node != null)
{
BeginInvoke(new Action(() => Other.Text = "Иные лица:\n" + node[0].InnerText.Trim()));
}
node = html.DocumentNode.SelectNodes("//*[@id='gr_case_judges page-break']/table/tbody/tr/td/div/ul/li");
if (node != null)
{
BeginInvoke(new Action(() => judjeName.Text = "Имя судьи:\n" + node[0].InnerText.Trim()));
}
}
}
}
catch(Exception exp)
{
MessageBox.Show(exp.Message);
}
// if (node != null)
// {
// browser.ExecuteScriptAsync("document.evaluate('//*[@id='b-case-header']/ul[2]/li[4]/a', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.click();");
// }
}
}
void button1_Click(object sender, EventArgs e)
{
browser.Load($"https://kad.arbitr.ru/Card?number={textBox1.Text}");
}
void InitializeChromium()
{
CefSettings settings = new CefSettings();
Cef.Initialize(settings);
browser = new ChromiumWebBrowser("https://kad.arbitr.ru");
Controls.Add(browser);
browser.Dock = DockStyle.Fill;
}
void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
Cef.Shutdown();
}
}
}