mercredi 2 septembre 2020

how to set a TextBox text inside a wpf application to the value of a specific html element in a given webpage (url)?

I want to pass the url of a webpage containing a <span id="spanID"> value </span> tag to a method like setTextBoxText(string url, string id) which is written in a wpf application codeBehind (MainWindow.xaml.cs) and set the Text of a specific TextBox Control to the span value, without loading the webpage. (for Ex. tracking price of a product in amazon)

I prefer to execute JavaScript code to get value of html elements and set the content of wpf controls to the result of the js code (function)

something like this:

public partial class MainWindow : Window
{
    string url = "https://websiteaddress.com/rest";
    setTextBoxText(url, "spanID");

    static void setTextBoxText(string url, string id)
    {
        // code to get document by given url
        txtPrice.Text = getHtmlElementValue(id);
    }

    string getHtmlElementValue(string id)
    {
        // what code should be written here?
        // any combination of js and c#?
        // var result = document.getElementById(id).textContent;
        // return result;
    }
}



Aucun commentaire:

Enregistrer un commentaire