Hey I have a problem with these blocks. My purpose is to get the images’ links of a site, but when I try to do that, I get nothing (both on companion and apk). I am sure I get the html because I can show it with the label, but the label does not show the html elements and neither does the “ParseFailed” error message. I’m not sure if the attribute is right, but in any case I don’t get errors… (I’m using HtmlUtils extension)
Check if you are using correct attribute or not.
<div id="eventTTL" style="text-transform: uppercase; font-weight: 900;" eventTTL="4583476000">5 days 07:14:41</div>
In these lines, if we want to get text “5 days 07:14:41”, then we will use “eventTTL” as attribute. This is how we use it in
Credit for HTML lines: Stackoverflow.
It seems image’s link can’t be get using img src attribute.
You should instead try to get all img elements and then get desired element’s HTML.
Then try to get src attribute value.
I have tried your example, but it no works. So I have set a “check string” but it is no shown and neither the error message is shown… seems the problem is in “ParseHtmlFromString” block
No. You are using wrong block.
eventTTL is an id not an attribute. Use these blocks.
Don’t get confused by
global name block. It is a global variable which contains the HTML.
For your information,
The id attribute specifies a unique id for an HTML element whereas HTML attributes are special words used inside the opening tag to control the element’s behaviour.
Hope it helps.
First set those string in the global variable and then use that variable in the string. Just like I did. I have checked those blocks and got the result.
protip: what about revealing the error you get in the ParseFailed event?
generally it helps to provide as much information as possible, so someone else is able to help… to just say “does not work” obviously does not help anyone very much, does it?
I tried to do as you told me, but there are several problems First of all, I tried in the companion using the block “ParseHtmlFromSting” in the initialization and I didn’t get anything (the label remained with the default text “Text for label 1”). Then I always tried in the Companion by putting the block “ParseHtmlFromString” after pressing the button (as you did) and after pressing the button twice in succession (pressing once nothing happened), either it worked or I got a message of error. Finally I compiled the apk and in the video you can see what happens (I always have to press the button twice to make it work or to get an error)… if you look until the end you will understand that something strange happens
Sometimes the variable is not available at runtime and that’s the reason why you get error. You can try
if-else block to overcome those errors.
What condition should I put in the “if-else” block?
If the HTML body is not null, then parse HTML from String.
Try it. Maybe, you can get your solution.
I tried to make my final program but it doesn’t work anyway. I press the button several times and nothing happens and then the “runtime” error appears… (I’m quite sure the selector is good, since I have copied it by Google Inspector, so it could not be a cause…)
Let’s wait for any (CSS+HTML) expert to give the solution as I am only familiar with a bit of HTML.
Don’t worry, thank you for all