How do you access specific elements from a web API?
2 次查看(过去 30 天)
显示 更早的评论
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.
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!
0 个评论
回答(1 个)
Walter Roberson
2016-6-19
编辑:Walter Roberson
2016-6-19
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Web Services 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!