iOS a 标签链接:<a href ="http://www.baidu.com">xxxx</a>提取xxxx的3种方法
来源:互联网 发布:资生堂化妆水知乎 编辑:程序博客网 时间:2024/04/19 12:35
突发奇想,想做个分析新浪微博粉丝的应用。要提取出来新浪微博的小尾巴。
//请求获取最新的一条微博
- (void)timelineButtonPressed
{
SinaWeibo *sinaweibo = [self sinaweibo];
// [sinaweibo requestWithURL:@"statuses/user_timeline.json"
// params:[NSMutableDictionary dictionaryWithObject:sinaweibo.userID forKey:@"uid"]
// httpMethod:@"GET"
// delegate:self];
[sinaweibo requestWithURL:@"statuses/home_timeline.json"
params:nil
httpMethod:@"GET"
delegate:self];
}
{
SinaWeibo *sinaweibo = [self sinaweibo];
// [sinaweibo requestWithURL:@"statuses/user_timeline.json"
// params:[NSMutableDictionary dictionaryWithObject:sinaweibo.userID forKey:@"uid"]
// httpMethod:@"GET"
// delegate:self];
[sinaweibo requestWithURL:@"statuses/home_timeline.json"
params:nil
httpMethod:@"GET"
delegate:self];
}
- (void)request:(SinaWeiboRequest *)request didFinishLoadingWithResult:(id)result
{
{
//最新一条微博
if ([request.url hasSuffix:@"statuses/home_timeline.json"])
{
[statuses release];
if ([request.url hasSuffix:@"statuses/home_timeline.json"])
{
[statuses release];
//请求成功,返回一个json,提取出来 statuses字段放进一个数组里
statuses = [[result objectForKey:@"statuses"] retain];
NSDictionary *dic=[statuses objectAtIndex:0];
statuses = [[result objectForKey:@"statuses"] retain];
NSDictionary *dic=[statuses objectAtIndex:0];
//source关键字对应的value 就是微博的来源,如<a href="http://app.weibo.com/t/feed/3ciyef" rel="nofollow">脉搏网</a> 前面地址是微博应用的地址,脉搏网就是我们要提取出来的尾巴
NSString *string = [dic objectForKey:@"source"];
NSString *string = [dic objectForKey:@"source"];
//用>分割字符串,放进数组里,取出第二个元素,截取字符串 就可得到脉搏网
NSArray *array=[string componentsSeparatedByString:@">"];
NSString *separateString=[array objectAtIndex:1];
NSLog(@"%@",[separateString substringToIndex:(separateString.length-3)]);
//用来获取json statuses字段里的 所有关键字key 并打印出来key 和对应的value 从中发现source字段使我们所需要的
// for (int i=0; i<dic.allKeys.count; i++)
// {
// NSLog(@"key==%@",[dic.allKeys objectAtIndex:i]);
// NSLog(@"value==%@",[dic objectForKey:[dic.allKeys objectAtIndex:i]]);
// }
}
NSArray *array=[string componentsSeparatedByString:@">"];
NSString *separateString=[array objectAtIndex:1];
NSLog(@"%@",[separateString substringToIndex:(separateString.length-3)]);
//用来获取json statuses字段里的 所有关键字key 并打印出来key 和对应的value 从中发现source字段使我们所需要的
// for (int i=0; i<dic.allKeys.count; i++)
// {
// NSLog(@"key==%@",[dic.allKeys objectAtIndex:i]);
// NSLog(@"value==%@",[dic objectForKey:[dic.allKeys objectAtIndex:i]]);
// }
}
}
<a href="http://app.weibo.com/t/feed/3ciyef" rel="nofollow">脉搏网</a> ,取出脉搏网有三种方法:
1、正则表达式
<a .*>(\d+|\D+)</a>
2、字符串处理,提取><之间的值
3、分割字符串,就是上面例子里的写法。
阅读全文
0 0
- iOS a 标签链接:<a href ="http://www.baidu.com">xxxx</a>提取xxxx的3种方法
- ios菜鸟之路:<a href ="http://www.baidu.com">xxxx</a>提取xxxx的3种方法
- <a href="<%=request.getContextPath()%>/XXXX.jsp"> 和<a href="XXXX.jsp"> 的区别?
- a标签的href
- ------<a href="http://www.itheima.com" target="blank">Java培训、Android培训、iOS培训、.Net培训</a>、期待与您交流! ----
- ------<a href="http://www.itheima.com" target="blank">Java培训、Android培训、iOS培训、.Net培训</a>、期待与您交流! ----
- ------<a href="http://www.itheima.com" target="blank">Java培训、Android培训、iOS培训、.Net培训</a>、期待与您交流! ----
- ------<a href="http://www.itheima.com" target="blank">Java培训、Android培训、iOS培训、.Net培训</a>、期待与您交流! ----
- ------<a href="http://www.itheima.com" target="blank">Java培训、Android培训、iOS培训、.Net培训</a>、期待与您交流! ----
- ------<a href="http://www.itheima.com" target="blank">Java培训、Android培训、iOS培训、.Net培训</a>、期待与您交流! ----
- ------<a href="http://www.itheima.com" target="blank">Java培训、Android培训、iOS培训、.Net培训</a>、期待与您交流! ----
- ------<a href="http://www.itheima.com" target="blank">Java培训、Android培训、iOS培训、.Net培训</a>、期待与您交流! ----
- ------<a href="http://www.itheima.com" target="blank">Java培训、Android培训、iOS培训、.Net培训</a>、期待与您交流! ----
- a href链接弹出新窗口的方法
- <a href="mailto:XXXX">在Android或iPhone上点击无法生效
- 提取a标签的链接文字
- 使用html <a href=""/>标签连接action的方法
- 使用html <a href=""/>标签连接action的方法
- Java线程
- 【Android】如何实现启动APP时引导页、欢迎页功能之(一)引导页功能的实现
- kmp
- Android sqlite SQL语句
- vim编辑操作
- iOS a 标签链接:<a href ="http://www.baidu.com">xxxx</a>提取xxxx的3种方法
- Eclipse以及Java各个版本的下载地址
- 21day 多线程(GCD)
- 多线程(7)
- maven常用插件配置
- 一步一步教你用Kcptun给Shadowsocks加速!
- Spring中实现多数据源事务管理
- 查看linux TCP连接数
- redis在centos下安装与开机自启配置