U
U
Uncle Bogdan2021-06-10 12:26:15
Parsing
Uncle Bogdan, 2021-06-10 12:26:15

Why does the error appear after loading the page?

The error appears after pressing the button, if the textbox says: A56-49015/2021 (there is such a site). Sometimes it doesn't give anything at all, but it doesn't click on the element.. Like this, it gives out:

60c1d84acb0ed304034373.png

Code:

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.Tasks;
using System.Windows.Forms;
using CefSharp;
using CefSharp.WinForms;
using HtmlAgilityPack; //почему-то пишет что директива using не нужна, хотя вроде я использую.

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)
        {
            var source = await browser.EvaluateScriptAsync("document.documentElement.outerHTML");

            if(source != null)
            {
                html.LoadHtml((string)source.Result);

                var node = html.DocumentNode.SelectNodes("//*[@id='b-case-header']/ul[2]/li[4]/a");

                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();
        }
    }
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question