iphone - 如何从网页获取数据到NSString

标签 iphone ios sdk nsstring

是否可以(使用 ASIHTTPRequest 或其他方式)从网页获取数据并将其保存到 NSString 变量?

我在网页上有以下代码:

<span id="ctl06_ctl06_spDailySMSSection">RANDOM TEXT xxxxxxxxxxxxxxxxxxxxxxxxxx <strong><span id="ctl06_ctl06_spNumberOfDailySMSLeft"></span></strong> AGAIN RANDOM TEXT.</span>

如何从字段 ctl06_ctl06_spNumberOfDailySMSLeft 获取数据并在 iOS 应用程序中使用它?

提前致谢

最佳答案

要正确地做到这一点,您需要一个 NSXMLParser,它使用正确的标签并接收您需要解析的属性。如果您正在寻找不太通用的解决方案:

    NSString *urlStr = [NSString stringWithContentsOfURL:[NSURL URLWithString:@"http://your.url"] encoding:NSUTF8StringEncoding error:nil];

关于iphone - 如何从网页获取数据到NSString,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11283754/

相关文章:

iphone - Uitableview 从 Internet 获取异步数据,屏幕为空白,直到超时或数据可用

iphone - UIWebView 不调用 UIScrollViewDelegate 方法

ios - 将标记 infoWindow 添加到 Mapbox 注释

ios - IBInspectable 出现问题并从 xib 为 Interface Builder 加载 View

iphone - 适用于 IOS 的 XML 解析器 SDK

ios - 在 swift 中使用 FBSession.FBSessionState 值

ios - 使用 iPhone 7 Plus 相机同时拍照

iphone - 从应用程序中关闭自动锁定

iphone - 在 customtableviewcell 中加载并设置其 IBOUTLETS 时请求成员错误

java - Android 库错误