开发者

How to parse the content of the tag with attribute in iphone?

开发者 https://www.devze.com 2022-12-22 01:45 出处:网络
I am new to iphone development.I want to parse and retrieve a particular content from the HTML file at the url.I have a sample code from this link http://blog.objectgraph.com/index.php/2010/02/24/pars

I am new to iphone development.I want to parse and retrieve a particular content from the HTML file at the url.I have a sample code from this link http://blog.objectgraph.com/index.php/2010/02/24/parsing-html-iphone-development/

 NSData *htmlData = [开发者_如何学编程[NSString stringWithContentsOfURL:[NSURL URLWithString: @"http://www.objectgraph.com/contact.html"]] dataUsingEncoding:NSUTF8StringEncoding];
 TFHpple *xpathParser = [[TFHpple alloc] initWithHTMLData:htmlData];  
 NSArray *elements  = [xpathParser search:@"//h3"]; // get the page title
 TFHppleElement *element = [elements objectAtIndex:0];
 NSString *h3Tag = [element content];  
 NSLog(h3Tag);
 mLabel.text = h3Tag;

They are retrieving the content in the h3 tag of the source , it displays properly contact us .I have changed the url as stack overflow and searched for title ,it retrieves the title properly.But i am not able to retrieve the content of the attributes of tags.Please help me out.Please guide me.Thanks


you can use //h3[@attribute='something'] in your query

or

you can use [element attributes] to get all associated with that particular attribute.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号