开发者

Returning a tag name with Hpple HTML Parser?

开发者 https://www.devze.com 2023-03-12 13:07 出处:网络
How do i grab the URL_TO_GRAB, with Hpple/Xpath for iPhone? Do i need to use some regex? <div clas开发者_运维技巧s=\"content\">

How do i grab the URL_TO_GRAB, with Hpple/Xpath for iPhone? Do i need to use some regex?

<div clas开发者_运维技巧s="content">
  <a href="URL_TO_GRAB"> Link </a>
</div>

Thanks a bunch.


You should be able to get it like this,

NSArray * elements = [doc search:@"//a"];
for ( TFHppleElement * element in elements ) {
    NSString * URLString = [[element attributes] objectForKey:@"href"];
    NSLog(@"%@", URLString);
}

This matches all anchor links and prints their urls.

0

精彩评论

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