so here is the problem. I am currently creating an Android app that is going to require me to parse some html so i can display it on the app screen.
I don’t know how to do that properly and was wondering if you guys could point me in the right direction or show me a good guide.
What I want to do is go through the html code and take out certain items (specifically the food items, you will see in a minute). I don’t want to just link the person to the website or use webview to display the webpage in the app cause I personally feel like that doesn’t look good. What i want to do is pull the food items from the html and then just put that part on my app in the form of a string or something.
—–Here is a bit of the html from the site I am using for reference——
enter code here
<a href="http://www.campusdish.com/en-US/CSMA/OldDominion/Locations/rda.aspx?RCN=m784&MI=122&RN=CEREAL HOT GRITS" OnClick="javascript: NewWindow('http://www.campusdish.com/en-US/CSMA/OldDominion/Locations/rda.aspx?RCN=m784&MI=122&RN=CEREAL HOT GRITS', 'RDA_window', 'width=450, height=600, scrollbars=no, toolbar=no, directories=no, status=no, menubar=no, copyhistory=no');return false" Class="recipeLink">CEREAL HOT GRITS</a>
<br>
</td>
</tr>
</table>
</div>
</td>
</tr>
<tr>
<td>
<div class="menuTxt">
<table cellpadding="0" cellspacing="0" border="0" bordercolor="green">
<tr valign="top">
<td colspan="3">
<a href="http://www.campusdish.com/en-US/CSMA/OldDominion/Locations/rda.aspx?RCN=m860&MI=122&RN=PANCAKES BUTTERMILK" OnClick="javascript: NewWindow('http://www.campusdish.com/en-US/CSMA/OldDominion/Locations/rda.aspx?RCN=m860&MI=122&RN=PANCAKES BUTTERMILK', 'RDA_window', 'width=450, height=600, scrollbars=no, toolbar=no, directories=no, status=no, menubar=no, copyhistory=no');return false" Class="recipeLink">PANCAKES BUTTERMILK </a>
——end html——-
So I want to just extract the words “CEREAL HOT GRITS” and “PANCAKES BUTTERMILK” for example.
Please and thank you for your help!
It might not be the most efficient way, but if you take the HTML source code and put it in a string, and then parse through it that way line by line. Whenever you hit a line with
<a hrefat the beginning, then you can check it, and see if it is a food item (don’t know how you’d do that without know the rest of the links, but there is probably a different structure or something, or food items might start after link 7 or something. Websites usually have a recognizable pattern). If it is a food item, then grab the link (for the image) and the name, or whatever you need.