Fetch value from website

Greetings all.
I created a radio stream app. I want to show in a label the song that is playing as current song. In my blocks i have created the web viewer, but it doesn't fetch the html element by id as requested, instead it's fetching the whole website and displays it in the webViewer component.
I followed the solution in this topic Data from html web page in label of AI2 but it seems that something i'm missing.
My blocks for this particular functionality are these.


My JavaScript is window.AppInventor.setWebViewString(document.getElementById("hp1").innerHTML

Any ideas what i'm doing wrong?

Thanks in advance.

Did you miss the closing bracket on the end ?

The js code in the block is this "window.AppInventor.setWebViewString(document.getElementById("hp1").innerHTML"

Yes, you need a closing bracket at the end...

window.AppInventor.setWebViewString(document.getElementById("hp1").innerHTML)
1 Like

Yes, i forgot it, but put it doesn't change anything. Still the whole webpage appears.

The whole web page will appear

You need to use the WebviewString change block to return the new value of the webviewstring which should be the innerHTML of hp1.

The webviewer does not need to be visible for this to work.

Ok thank's for helping me out on this, but i think i do use the WebviewString change block. And yes you're right again i set WebViewer invisible. Maybe something i dont get. Do i ask to much if i ask for an example?

No problem

You're right again. Being focused on why i cant see the current song title, i didn't change the default black text color from black to white. I do have a black background. Ok now this is solved. So you're saying to create timer for fetching the value of the html element because it changes every time, right? I do have another question, if you don;t mind. Actually there is a list picker which you can choose from 5 different streams. Can i check with the list_streams block that i've created the text value e.g stream1,stream2, e.tc. with an if else if condition and according to text to display the current song? Each stream has different id, so we're ok in that.

Ok since no one else commented. I want to thank TIMAI2 for his valuable advices because i forgot small but crucial details. I will be back with my proposal for a stream radio app.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.