Reading real-time value from HTML element in URL page using jQuery

百般思念 提交于 2019-12-14 04:09:18

问题


I've got this website: https://coinyep.com/he/ex/ETH-ILS

Inside this URL web page, there is an input element, and its HTML id is: "coinyep-input2".

I need to read its value (= approximately 637.49 ILS) using jQuery in Visual Studio.

So far, I tried everything, no success. Any help will be appreciated.

For example, in jQuery there is a command :

 document.getElementById("coinyep-input2"); 

==> I need to do the same thing but to do it from the URL page in order to get values in real-time (exchange rates).


回答1:


Does this help?

$("#coinyep-input2").attr("data-valuta");

or

$("#coinyep-input2").attr("data-value");

or

$("#coinyep-input2").val();



回答2:


For now, I found solution in C# (server), using it by Razor on the client [Based on RSS URL]:

   public float getExchangeRate_ETH_To_ILS()
    {
        float exchangeRate;
        string[] words;
        int indexOfExchangeRate;

        using (var client = new WebClient())
        {
            try
            {
                var htmlPage = client.DownloadString("https://coinyep.com/he/rss/ETH-ILS.xml");
                words = htmlPage.Split(' ');
                indexOfExchangeRate = words.IndexOf("ILS");
                exchangeRate = (float)Convert.ToDouble(words[indexOfExchangeRate - 1]);

            }
             catch(Exception e)
             {                        
                exchangeRate = -1;
             }
        }
        return exchangeRate;
    }

in the client, I use this fucntion via model (Razor):

  var cal1 = @Model.getExchangeRate_ETH_To_ILS(); 

But there is a risk: if the template of the RSS will be changed, we are in trouble.



来源:https://stackoverflow.com/questions/58662153/reading-real-time-value-from-html-element-in-url-page-using-jquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!