StrokesPlus.net Forum
»
General Discussion
»
Scripts
»
Can the S+program obtain the attribute values of the specified elements in
Rank: Advanced Member
Groups: Approved
Joined: 9/26/2018(UTC) Posts: 69  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;/
|
|
|
|
Rank: Administration
Groups: Translators, Members, Administrators Joined: 1/11/2018(UTC) Posts: 1,294  Location: Tampa, FL Thanks: 28 times Was thanked: 404 time(s) in 349 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
|
|
|
|
Rank: Administration
Groups: Translators, Members, Administrators Joined: 1/11/2018(UTC) Posts: 1,294  Location: Tampa, FL Thanks: 28 times Was thanked: 404 time(s) in 349 post(s)
|
You can replace the URL with direct HTML, then use native JavaScript to find the attribute.
|
|
|
|
Rank: Advanced Member
Groups: Approved
Joined: 9/26/2018(UTC) Posts: 69  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
|
|
|
|
StrokesPlus.net Forum
»
General Discussion
»
Scripts
»
Can the S+program obtain the attribute values of the specified elements in
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.
Important Information:
The StrokesPlus.net Forum uses cookies. By continuing to browse this site, you are agreeing to our use of cookies.
More Details
Close