2013-05-07 142 views
-2

如何訪問網站並將網站組件轉換爲字符串。例如從Facebook的帖子中獲取信息。我已經做了一些搜索,但找不到任何好的教程或任何有用的東西。將網頁源代碼轉換爲NSString

+0

獲取一個HTML解析器 – Kevin 2013-05-07 00:23:22

+0

所以解析HTML,寫入文件的應用程序可以訪問,然後呢? – 2013-05-07 00:30:49

+1

使用+(id)stringWithContentsOfURL:(NSURL *)url編碼:(NSStringEncoding)enc error:(NSError **)error'將想要解析的網頁下載到'NSString'中,然後將其傳遞給HTML解析器並提取您感興趣的元素。 – Kevin 2013-05-07 00:43:24

回答

1

試試看本教程。它應該讓你更加熟悉這個主題,並在正確的軌道上開始你。

因爲它在教程開始狀態...

How to Parse HTML on iOS

Let’s say you want to find some information inside a web page and display it in a custom way in your app. This technique is called 「scraping.」 Let’s also assume you’ve thought through alternatives to scraping web pages from inside your app, and are pretty sure that’s what you want to do. Well then you get to the question – how can you programmatically dig through the HTML and find the part you’re looking for, in the most robust way possible? Believe it or not, regular expressions won’t cut it! Well, in this tutorial you’ll find out how! You’ll get hands-on experience with parsing HTML into an Objective-C data model that your apps can use.

http://www.raywenderlich.com/14172/how-to-parse-html-on-ios

+0

完美!謝謝! – 2013-05-07 03:42:34

+0

如果您可以總結鏈接頁面,這將是一個更好的答案。就目前而言,如果頁面移動或消失,這個答案將毫無用處。 – Caleb 2013-05-07 12:55:56