是否可以将网页的内容读取为字符串,以便我可以解析出数据? [英] Is it possible to read the contents of a web page into a string so i can parse out the data?

查看:98
本文介绍了是否可以将网页的内容读取为字符串,以便我可以解析出数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够让我的iPhone将URL(或实际上是url指向的文件)加载到字符串中.我希望能够执行此操作的原因是,这样我就可以解析字符串以查找标签并从中提取一些值.

I'd like to be able to get my iphone to load a URL( or really the file that the url points to) into a string. The reason I want to be able to do this is so that I can then parse the string looking for tags and extract some values from it.

文件主要是网页,例如html或.asp等.

The files are mostly webpages so html or .asp etc.

有人能给我一些暗示,我需要做什么来实现这种目标吗?

Anybody able to give me some hints on what I need to do to achieve this kinda of thing?

非常感谢, -代码

推荐答案

首先获取URL

NSURL *anUrl = [NSURL URLWithString:@"http://google.com"];

然后将其转换为字符串

NSError *error;
NSString *htmlString = [NSString stringWithContentsOfURL:anUrl encoding:NSUTF8Encoding error:&error];

更新:

有关于从从那里您可以使用下载的数据的字符串表示形式

From there you can get the string representation of the downloaded data using

NSString *htmlString = [[NSString alloc] initWithData:urlData encoding:NSUTF8Encoding];

这篇关于是否可以将网页的内容读取为字符串,以便我可以解析出数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆