How do you access specific elements from a web API?

2 visualizzazioni (ultimi 30 giorni)
I have written some ADC Software (Attitude determination and control), however I would really like to test it out with some "live data". I think it'd be cool to run my code using live updates from the space station. As of right now, the only thing I have no idea how to do is how to actually interface with a web API.
So lets assume that the data is coming from this website: http://iss.astroviewer.net/
If I look at the elements on the page, I see that the position data for the ISS appears shortly after a line that says:
<p class="cockpitData" id="gpt">
I thought I could write something like this to get the data I wanted:
contents = urlread('http://iss.astroviewer.net/');
searchString = 'Ground point</p>';
location = strfind(contents, searchString);
subString = contents(location:(location +80))
Unfortunately this doesn't work. It gives me the following:
<p class="cockpitData" id="gpt"> <br /> </p>
So in the place where the location data SHOULD be is this weird "nbsp" thing. I looked it up and it appears to mean "non-breaking space". However I have no idea what this means.
I have no experience interacting with web API, but I'm going to continue reading and playing around with stuff to see if I can figure something out. Any help would be greatly appreciated though!

Risposte (1)

Walter Roberson
Walter Roberson il 19 Giu 2016
Modificato: Walter Roberson il 19 Giu 2016
HTML is a layout language. One of the services it provides is to "flow" text into available width, breaking up the text at "nice" boundaries if necessary to fit into the available width. By default, space characters are understood to be places where it is acceptable to do line breaks. However, there are cases where you need to put in blanks for positioning purposes and it is inappropriate to allow line breaks at those places. In such a case, you can use the token, the non-breaking space, which is a blank that HTML is not permitted to do a line break at.
This turns out to have a number of uses in HTML in practice. For example, try creating a hyperline with no associated text: href = ""</a>
<A HREF="http://somewhere.org"> </A>
HTML will normally see the several blanks and consolidate them all into one blank and then when it renders it trims off leading and trailing blanks -- so what you end up with is a zero-width hyperlink. The work-around is to put in a space that is not permitted to be treated that way, a space that is required to take up actual room (equivalent to the width of an 'n' if I recall correctly) -- a non-breaking space < >
<A HREF="http://somewhere.org"> </A>
When tables are being constructed, it is common for widths of columns to be automatically determined. If you want to be sure that a minimum width is allocated for a column, but you happen to be emitting an empty cell, then you can to be sure that HTML will not decide that the column does not need to be given screen space.
It is fairly common in HTML items to use one or more to represent empty space. When you encounter them and need to parse them, then substitute plain blanks for them before parsing.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by