【发布时间】:2012-04-09 01:15:20
【问题描述】:
我花了大约 16 个小时研究和尝试不同的代码更改,但无法弄清楚这一点。我有一个使用 ASIHTTPrequest 使用网站的 iOS 应用程序:
-(void)refresh{
NSURL *url = [NSURL URLWithString@"http://undignified.podbean.com/"];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request startSynchronous];
NSString *response = [request responseString];
NSLog(@"%@",response];
}
以上代码返回网站源代码并通过 NSLog 将其输出到控制台。我试图实现的目标是通过“responseString”搜索以 *.mp3 结尾的 URL,将它们加载到数组中,最后将 mp3 URL 加载到 UITableView 中。
总结一下:
- 通过 ASIHTTPRequest 使用网站数据
- 尝试在 responseString 中搜索所有具有 *.mp3 扩展名的链接并将它们加载到数组中。
- 将解析后的链接添加到 UITableView。
我认为在这个路口我已经尝试了太多事情来做出任何合理的判断。任何朝着正确方向提出的建议或推动都将不胜感激。
以下是响应示例 (HTML)。请注意,这只是一个 sn-p,因为整个 HTML 源代码相当大,但这包括 mp3 文件的一部分:
a href="http://undignified.podbean.com/mf/web/ih2x8r/UndignifiedShow01.mp3" target="new"><img src="http://www.podbean.com/wp-content/plugins/podpress/images/audio_mp3_button.png" border="0" align="top" class="podPress_imgicon" alt="icon for podbean" /></a> Standard Podcasts [00:40:24m]: <a href="javascript:void(null);" onclick="podPressShowHidePlayerDiv('podPressPlayerSpace_2649518', 'mp3Player_2649518_0', '300:30', 'http://undignified.podbean.com/mf/play/ih2x8r/UndignifiedShow01.mp3'); return false;"><span id="podPressPlayerSpace_2649518_label_mp3Player_2649518_0">Play Now</span></a> | <a href="javascript:void(null);" onclick="window.open ('http://undignified.podbean.com/wp-content/plugins/podpress/podpress_backend.php?podPressPlayerAutoPlay=yes&standalone=yes&action=showplayer&pbid=0&b=458211&id=2649518&filename=http://undignified.podbean.com/mf/play/ih2x8r/UndignifiedShow01.mp3', 'podPressPlayer', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=660,height=360'); return false;">Play in Popup</a> | <a href="http://www.podbean.com/podcast-download?b=458211&f=http://undignified.podbean.com/mf/web/ih2x8r/UndignifiedShow01.mp3" target="26108">Download</a> | <a href="http://www.podbean.com/podcast-players?b=458211&p=2649518&f=http://undignified.podbean.com/mf/play/ih2x8r/UndignifiedShow01.mp3" target="38148">Embeddable Player</a> | <a>Hits (214)</a><br/
【问题讨论】:
-
如果您要发布您尝试解析的实际 URL 或响应的良好示例,这个问题会更容易回答。
-
添加了响应的 URL 和示例。
-
您使用 ASIHTTPRequest 标记了您的问题,并且还显示了您的请求初始化程序的 sn-p,但随后您提到了 NSURLConnection 不用于 ASIHTTPRequest - 请理顺这一点。对于潜在的时间问题,测量但不要假设。
-
我已经稍微清理了这个问题,并删除了 Till 感到困惑的部分。
标签: ios asihttprequest