2

I'm fetching an a HTML page and try to get some of it's content to show it in a table view. Following the documentation I tried NSXMLDocument and NSXmlParser but could not get any of them to give me the right data back :-(

The page I'm trying to scrap is http://www.instapaper.com/u

The code I'm using is

NSXMLDocument * doc = [[NSXMLDocument alloc]
                        initWithXMLString: data
                        options: NSXMLDocumentTidyHTML
                        error: &error];
NSArray* rows = [doc nodesForXPath:@"//div[class='tableViewCell']" error:&error];

to get DIVs with class=tableViewCell.

If I only search for //div I get back a lots of them, but filtering by class seems not to be working :-(

Any idea what I'm doing wrong?

Thanks for any help, Miguel

1

1 Answer 1

13

I guess you are trying to filter by the class attribute? then you would need to add an @ to your xpath:

//div[@class='tableViewCell']

yet, i cannot find a div having this class?

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks a lot Dennis. I thought I did try it this way... but it seems I did something wrong when I did. Now it works perfectly :-)
One further question... how would I do if the class attribute value is "tableViewCell someOtherClassValue"? Right now it only gives me back the nodes which only have tableViewCell as value.
you could use //div[contains(string(@class),"tableViewCell")]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.