是否可以(使用 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/