parsing a table using html agility pack in unity?

76 Views Asked by At

I am not a programmer so i have no experience. the issue is that I managed to parse some information from this website text but the table at the bottom that has the Announcement Date and the rest of the columns cannot be parsed. I think the reason being it gets updated when the page loads by sending a request to fetch the information (this is just the opinion of an unknowledgeable guy).

How can I parse it with html agility pack or any other tool and implement it in unity, is it even possible? if not how can I go around it and parse it?

I did try inspecting it and copying the xpath //*[@id="issuerTable"]/tbody/tr[1]/td[3].But obviously It did not work because it is has a tbody and I understand that it is a bad thing.

using UnityEngine;
using UnityEngine.UI;
using HtmlAgilityPack;
using System;
using System.Collections;

public class WebPageParser : MonoBehaviour
{
public InputField symbolInput;
public Text resultText;
public Button parseButton;

[SerializeField]
private string xpath = "//*[@id='issuerTable']/tbody/tr[1]/td[3]";


private string defaultSymbol = "2222";

private void Start()
{
    
    symbolInput.text = defaultSymbol;

    parseButton.onClick.AddListener(StartParseDelay);
}

private void StartParseDelay()
{
    StartCoroutine(ParseWithDelay(3.0f));
}

private IEnumerator ParseWithDelay(float delayInSeconds)
{
    
    yield return new WaitForSeconds(delayInSeconds);

    string symbol = symbolInput.text;

   
    string url ="https://www.saudiexchange.sa/wps/portal/saudiexchange/newsandreports/issuer-financial-calendars/dividends/!ut/p/z1/hYzLCsIwEAA_aVcT01xLRdJKqW19ZS-SSNSSvpAixK-3njx6nGEYIDgD9ebV3M3UDL1pZ9YkLqtY4FJJLKRSEZabbSrTKkPcMdBzEP2CIi8TFMirgziuF5gxqIGAbKhDZ4cWNGecf01nnt5N-zC65OGuHnQOp3-r0Rv7voX4AyL4jHM!/";

    try
    {
        HtmlWeb web = new HtmlWeb();
        HtmlDocument doc = web.Load(url);

        
        HtmlNode node = doc.DocumentNode.SelectSingleNode(xpath);

        if (node != null)
        {
            // Get the inner text of the selected element
            string xpathResult = node.InnerText;
            resultText.text = $"XPath Result: {xpathResult}";
        }
        else
        {
            resultText.text = "XPath element not found on the 
    page.";
        }
    }
    catch (Exception e)
    {
        resultText.text = $"Error: {e.Message}";
    }
}
}
0

There are 0 best solutions below