Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

alexandergre

macrumors member
Original poster
Jul 28, 2009
58
0
hi. Im new here from another forum. moved here cuz nobody could answer this question:

1. go here: http://www.blocket.se/stockholm?ca=11
2. I want to show the items in that page in a UITableView
3. basicly, something like this.
4.All the information(Item´s title, thumnail, price, location, uploaded time&date) I need are located in the source code of the page.

The problem is that I have no clue how to do it.
I have one guessing though:
convert the HTML source code to XML.
in that way I can use xml to show the data in UITableView´s cells.

can you please help me?
 
You need to parse the html using the built in xml parser. Build a data structure that contains all the info you need for the table. That will be something like an array of dictionaries where each dictionary represents a row in the table. Display of this table will be straightforward.
 
You need to parse the html using the built in xml parser. Build a data structure that contains all the info you need for the table. That will be something like an array of dictionaries where each dictionary represents a row in the table. Display of this table will be straightforward.

You mean something like this:

Code:
url: [url]http://www.blocket.se/stockholm?ca=11[/url]
NSXMLParser *MyXmlParser = [[NSXMLParser alloc] initWithContentsOfURL:url];

can NsXMLParser parse html files??? :confused:
 
can NsXMLParser parse html files??? :confused:

Yes :D

I haven't used it for that. You should google and you'll find how others have used it for that and what other solutions there are. But basically the choices are to use an xml parser or regexes and I think you'll find that xml parsers are better for this task. Problem is that html pages may not be well formatted and this can cause the xml parser to have problems. If you only need it to parse a small number of pages then you may be ok.
 
You mean something like this:

Code:
url: [url]http://www.blocket.se/stockholm?ca=11[/url]
NSXMLParser *MyXmlParser = [[NSXMLParser alloc] initWithContentsOfURL:url];
That's a start, other than you'll need to redo that assignment of 'url'. You then need to code delegate methods to handle the actual parsing. Look at the SeismicXML sample app for more info on how this works.

can NsXMLParser parse html files??? :confused:
It can. But it'll be much more predictable if the HTML is structured so that it seems like XML (i.e. well-formed). You'll either want to make sure it comes in that way, or figure out some way to convert it to XHTML. Or take your chances... :)
 
The other alternative is to parse the HTML using the built-in Javascript interpreter, which may or may not be a more suitable language for the XML and string processing required. (I like the fact is has built-in regex.)

would you enlighten me what built in js interpreter you're talking about? i never heard of it :)
 
Yes :D

I haven't used it for that. You should google and you'll find how others have used it for that and what other solutions there are. But basically the choices are to use an xml parser or regexes and I think you'll find that xml parsers are better for this task. Problem is that html pages may not be well formatted and this can cause the xml parser to have problems. If you only need it to parse a small number of pages then you may be ok.

That's a start, other than you'll need to redo that assignment of 'url'. You then need to code delegate methods to handle the actual parsing. Look at the SeismicXML sample app for more info on how this works.


It can. But it'll be much more predictable if the HTML is structured so that it seems like XML (i.e. well-formed). You'll either want to make sure it comes in that way, or figure out some way to convert it to XHTML. Or take your chances... :)

Thank you very much for your time.
Im going to try it. :) :rolleyes: :apple:
 
The other alternative is to parse the HTML using the built-in Javascript interpreter, which may or may not be a more suitable language for the XML and string processing required. (I like the fact is has built-in regex.)
Although JavaScript does have regex, it doesn't have a built-in XML parser. Depending on your needs (i.e. parsing and extracting much of the XML vs. pulling out a small number of fields), you need to determine what is more suitable.
 
Although JavaScript does have regex, it doesn't have a built-in XML parser. Depending on your needs (i.e. parsing and extracting much of the XML vs. pulling out a small number of fields), you need to determine what is more suitable.

Hi,
how do you invoke javascript functions from ObjC level?
greets
 
So i have been struggling with this app all day long. I have fount a tutorial but cant see a single line in my TableView. anyways... I will continue with this tomorrow.

You can check the project if you want.



Every ad has this code: its very bad written. why didnt they use xml. oh gush
HTML:
<tr >

<th nowrap="nowrap" class="listing_thumbs_date">
		Igår<br>23:52
		
</th>
	
		<td class="listing_thumbs_image">
				
			<table cellspacing="0" cellpadding="0" class="clean_table shadowed_thumb">
				<tbody>
					<tr>
						<td><img src="/img/thumb_left_top.gif"></td>
						<td class="top_middle" valign="bottom" align="left"></td>
						<td></td>
					</tr>
					<tr>
						<td class="middle_left"></td>
						<td><a href="http://www.blocket.se/vasterbotten/Dragbil_med_bergtrailer_22815303.htm?ca=2&w=1"><img src="http://195.149.144.149/thumbs/54/5495739903.jpg" border="0" alt="Flera bilder" title="Flera bilder"></a></td>
						<td valign="top" class="extra_middle_right"><img src="/img/thumb_extra_right_top.gif"></td>
					</tr>
					<tr>
						<td></td>
						<td valign="top" class="extra_bottom_center"><img src="/img/thumb_extra_left_bottom.gif"></td>
						<td><img src="/img/thumb_extra_right_bottom.gif"></td>
					</tr>
				</tbody>
			</table>
		
		</td>
		
		
		
		
		
		
		
		
		<td nowrap="nowrap" class="thumbs_subject">
				<a href="http://www.blocket.se/vasterbotten/Dragbil_med_bergtrailer_22815303.htm?ca=2&w=1">
				Dragbil med bergtrailer
				
				</a><br>
				
				
				
					
						
						
						
						600 000:-
					
					
				
				
			</td>

			<td class="clean_links">

			<a href="http://www.blocket.se/li?ca=2&cg=1220&w=1" tabindex="-1" title="Visa annonser i kategorin Lastbil/Truck/Entreprenad">Lastbil/Truck/Entreprenad</a>


			(f) 

			

			<br>	

			
					<a href="http://www.blocket.se/vasterbotten/Dragbil_med_bergtrailer_22815303.htm?ca=2&w=1&th=mp" tabindex="-1" title="Visa annonsen på karta">Vilhelmina</a>
				
			
			</td>
			
		
	
</tr>


Just one question:
Is it possible to get the HTML source code and save it in a string file?
that would make every thing 100000% simpler.
 

Attachments

  • Blocket.zip
    636.2 KB · Views: 180
Hi Alex,

I also need to do the same thing as you mentioned in this post, could you help ? Fetch data from web or blog and put into UITableView. Thx alot.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.