StrokesPlus.net
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
liuchina  
#1 Posted : Sunday, November 6, 2022 12:38:07 PM(UTC)
liuchina

Rank: Advanced Member

Reputation:

Groups: Approved
Joined: 9/26/2018(UTC)
Posts: 73
China
Location: 北京

Thanks: 18 times
Was thanked: 1 time(s) in 1 post(s)
Hi Rob:
I used http request get to obtain an html file. Can the built-in function methods of the S+program be used to obtain the attribute values of the specified elements in the html file? Can you give me a sample code? Thank you.
Quote:
var httpClient = new HttpClient()
var url = new Uri(res);
var response = httpClient.GetAsync(url).Result;
var data = response.Content.ReadAsStringAsync().Result;/
Rob  
#2 Posted : Sunday, November 6, 2022 11:22:22 PM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 1,349
United States
Location: Tampa, FL

Thanks: 28 times
Was thanked: 416 time(s) in 354 post(s)
This is a very simple example.
Code:
// Callback used by the HTML window we create below
function attributeWindowCallback(val) 
{
    let obj = JSON.parse(val);
    if (obj.StrokesPlusHTMLWindow) {
        var handle = new IntPtr(parseInt(obj.StrokesPlusHTMLWindow.Handle))
        sp.StoreHandle("attributeWindowHandle",handle);
    } 
    else if (obj.action)
    {
        switch(obj.action) {
            case "Close":
                sp.WindowFromHandle(sp.GetStoredHandle("attributeWindowHandle")).SendClose();        
                break;
        }
    }
}

// Opens an HTML window to a URL (this post), waits 2 seconds, then looks for a div and shows an 
// alert with the html of the element, then closes the HTML window
sp.HTMLWindow("Find Element", //Window title
              "https://forum.strokesplus.net/posts/t8539-Can-the-Sprogram-obtain-the-attribute-values-of-the-specified-elements-in", 
              "attributeWindowCallback", //message callback
              `setTimeout(function(){ // Script to execute on document create
                 alert($('.selectionQuoteable').html());
                 window.chrome.webview.postMessage({ action: 'Close'});
               }, 2000);`, // Waits 2 seconds, then gets an element via jQuery
              "", // window ID
              false); // include jQuery/bootstrap - ignored for file/url
Rob  
#3 Posted : Sunday, November 6, 2022 11:23:09 PM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 1,349
United States
Location: Tampa, FL

Thanks: 28 times
Was thanked: 416 time(s) in 354 post(s)
You can replace the URL with direct HTML, then use native JavaScript to find the attribute.
liuchina  
#4 Posted : Tuesday, November 8, 2022 9:00:08 AM(UTC)
liuchina

Rank: Advanced Member

Reputation:

Groups: Approved
Joined: 9/26/2018(UTC)
Posts: 73
China
Location: 北京

Thanks: 18 times
Was thanked: 1 time(s) in 1 post(s)
@Rob Thank you very much for your reply. In fact, I encountered an unsolvable problem when I used S+to convert the html file into a js object
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.