ast1 ast1 - 2 months ago 6x
HTML Question

How to get a value of an HTML table in Objective-C?

I really hope someone can help me.

What I'm trying to do is get a value out of an HTML table in Xcode. Basically this is the HTML of the Website I'm trying to parse:

<tr class="stop dep-odd">
<td class="someClass">valueIWantToGet</td>
<td class="someOtherClass">someOtherValue</td>

So I want to get the Value between the tags and only the one with class="someClass".

My approach to this is: (Objective-C)

NSString *string = [webView stringByEvaluatingJavaScriptFromString:@"document.getElementsByClassName(someClass);"];

but it's returning an empty string @"".

I also tried with different search queries such as


but nothing's worked yet. Can someone please show me what I'm doing wrong? (I'm not experienced with JavaScript, so the issue may be obvious to someone with more knowledge, please don't judge me.)


Okay, I managed to do it. The solution was using:

NSString *string = [webView stringByEvaluatingJavaScriptFromString: @"document.getElementsByClassName('someClass')[1].innerHTML;"];

and it works now.