[HowTo] Read html tags from normal Variable with Structure Output

51 views
Skip to first unread message

francwalter

unread,
Oct 30, 2023, 6:12:29 AM10/30/23
to Tasker
Hallo
I read Native JSON and HTML Reading and I use it since a while, but since yet I used it only when I do some HTTP Requests, then I use the var. %http_data to get Tags and Values out of that HTML-Soup. Great feature!

Now, I want to get content from a variable containing only parts of HTML, e.g.:

Variable %html : 
<p>
  <strong>
    <font color="red">FirstText</font>
  </strong>
</p>
<p>
  <strong>
    <font color="green">NextText</font>
  </strong>
</p>

So to get e.g. the first content of the font-tag, here "FirstText", I just do this:

%html[font](1)

or also, here for the second font-content (NextText):

%html.font(2)

This is a very useful feature, thanks for it. The library behind it is (I think) from jsoup: Java HTML Parser
jsoup does a good job, but if the html-soup is too wrong, then it would fail. E.g. if I have such:

<p>
  SomeText
</p>
TaglessText

It wont be able to parse it, then it wouldnt be recognized as html at all.
But text like  <!-- TaglessText --> will work again :)

Thanks for that great feature!
frank
Tasker (direkt) 6.2.15-rc on Android 9.0



João Dias

unread,
Oct 30, 2023, 6:39:25 AM10/30/23
to tas...@googlegroups.com
Thanks Frank :) Glad you like the feature!

Thank you for your contact.

   Join: connect multiple devices (send pushes, remote SMS, notifications) on Android, Windows, Mac, Linux
   Tasker: customize/automate anything on your phone!
   AutoApps: add advanced functionality to Tasker via plugins

     

João Dias


francwalter

unread,
Nov 4, 2023, 4:44:52 PM11/4/23
to Tasker
What I still dont know is how to do something like getElementById() as in JavaScript.
This doesnt work:

Variable %html : 
<p>
  <div id="myid">SomeText</dive>
</p>
 
%html(#myid)

neither this:

%html[#myid]

How can I get an element from html by its ID? The innerHtml e.g.?

francwalter

unread,
Nov 5, 2023, 6:14:24 AM11/5/23
to Tasker
francwalter schrieb am Samstag, 4. November 2023 um 21:44:52 UTC+1:
What I still dont know is how to do something like getElementById() as in JavaScript.
This doesnt work:

Variable %html : 
<p>
  <div id="myid">SomeText</div>
</p>
 
%html(#myid)

This indeed does not work, but:
 
neither this:

%html[#myid]

This in fact works! Shows "SomeText"!

See the instruction here to try jsoup: Try soup
Or  documentation about jsoup elements here: Class Selector

So I was wrong, I tested it on Google (trying to find the ammount of hits of a search (id="result-stats") but Google does not allow a search just like this, need to accept the cookies-f.ck so I got a redirect (302) and no id=result-stats in my %html_data.
Didnt test thorrowly enough, sorry.


Reply all
Reply to author
Forward
0 new messages