我想使用这段代码在应用商店中解析我自己的应用的页面
NSError *error = nil;
NSURL *url = [NSURL URLWithString:@"https://itunes.apple.com/us/app/id892887222?ls=1&mt=8"];
NSStringEncoding encoding;
NSString *webData= [NSString stringWithContentsOfURL:url
encoding:encoding
error:&error];
webData 为 nil,[error localizedDescription]
显示无法打开文件“id892887222”。
我想发生这种情况是因为这个页面是动态的,是通过拉取数据库即时创建的,但是我如何获得这个页面的源代码?
最佳答案
此代码将页面的 HTML 作为 NSString 对象提供给我:
NSStringEncoding encoding;
NSError *error;
NSString *contentsOfAppleComAsString = [NSString stringWithContentsOfURL:[NSURL URLWithString:@"https://itunes.apple.com/us/app/id892887222?ls=1&mt=8"] usedEncoding:&encoding error:&error];
if(contentsOfAppleComAsString)
{
NSLog(@"contents of Apple.com is %@", contentsOfAppleComAsString);
} else {
NSLog(@"error from trying to get contents of Apple.com is %@", [error localizedDescription]);
}
关于html - 尝试在 App Store 上获取我的应用程序页面的 HTML 源代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26534015/