Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Parsing text from a website

I'm trying to parse text from a website into a label is this possible? if so what's the best way to go about it?

3 Answers

Jack Solomon
Jack Solomon
839 Points

Personally, I disagree. Have a look at a Ray Wenderlich (an iOS dev blog/tutorials) on how to parse HTML: http://www.raywenderlich.com/14172/how-to-parse-html-on-ios

If an API is available for the site you are querying data from, that would be ideal, but not many sites do, and parsing HTML isn't too hard. I was able to follow along with the tutorial (I have almost no HTML knowledge) with no difficulty.

James Barnett
James Barnett
39,199 Points

Actually I totally agree with what that blog article is saying ...

how can you programmatically dig through the HTML and find the part you’re looking for, in the most robust way possible? Believe it or not, regular expressions won’t cut it!

Scraping web pages from your app is not always the best choices

Do you own the content? If you own the content you’re scraping, no problem. But if you don’t, it’s kinda dodgy legally.

If you really want to be getting data from the web, you should consider using a web service instead that can return you nice, beautiful XML or JSON.

James Barnett
James Barnett
39,199 Points

In general that's a terrible idea, it's usually referred to as screen scraping as the only way to get that information is to download HTML and parse it.

What would be ideal?

I'm trying to parse the "Currently Tracking:" stats from www.threatconnect.com I'm not sure that an API would help.

James Barnett
James Barnett
39,199 Points

What would be ideal is if threatconnet.com exposed that data to you via an API call.