簡體   English   中英

如何解析 HTML?

[英]How can I parse HTML?

假設我有以下字符串:

NSString * str = "<a href="http://www.google.com"style="">
</br>
<a href="http://www.google.com" id="" style="">Come on</a>hello world"

我怎樣才能解析出錨標簽的值——“加油”?

我應該使用 HTMLNode.h 和 HTMLParser.h 嗎? 示例將不勝感激。

如果是 static,那么可以使用字符串操作將 substring 從標簽中取出

或者

如果它是動態的並且 html/xml 代碼不斷變化,那么您可以使用 NSXMLParser。 請記住,僅當數據為 XML 格式時,才應更優選使用 NSXMLParser。

http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSXMLParser_Class/Reference/Reference.html

希望這可以幫助。

libxml2非常擅長解析xml/html,請看這個鏈接: http://cocoawithlove.com/2008/10/using-libxml2-for-parsing-and-xpath.html

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM