iphone - 如何获取html文件的一部分?

标签 iphone html ios parsing xpath

我只想在所有 html 标签中获取网站的一部分:

<table></table>
...
<div><font>some <b>kind</b> of <i>individual</i> text I need</font></div>
...
<div>other things I don't need</div>

-> I only want this: <font>some <b>kind</b> of <i>individual</i> text I need</font>

我的目标是在 UIWebView 中用粗体标记和图像显示这部分。我尝试了一些 XPath 解析器,但这些解析器跳过了我想在 web View 中显示的标签。 在 Stackoverflow 上,我找到了一个使用 java 脚本的解决方案:extract-part-of-html-in-c-objective-c但我不知道这对我的 ios 应用程序有何帮助

希望有人能帮助我

最佳答案

您可能会发现这很有用:(请参阅本文中的演示)

http://api.jquery.com/html/

它几乎是你需要的一切,除了“使标签加粗”部分

更新:包括从单独的 url 获取内容

http://api.jquery.com/jQuery.get/

$.get("http://www.website_i_need_to_parce.com", function(data){

  /// work with "data" variable as you work with "document"

  var htmlStr = data.html().find('#someDiv');

});

调用之后——htmlStr 将包含 id="someDiv"的 div 的内容。如果您需要将这些内容粘贴为 html - 使用:

  $('#div_on_my_site_where_I_Want_to_paste_code').text(htmlStr);

关于iphone - 如何获取html文件的一部分?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7367196/

相关文章:

ios - 在 iPhone 中开发类似 eBay 或 AppStore 的应用程序

iphone - 游戏中心无法识别该游戏

html - 将 CSS 标注添加到工具提示

ios - viewDidUnload 中的内存管理——我应该将数组和对象都清零吗?

iphone - writeToFile 失败 - 如何调试它失败的原因(什么工具)?

ios - UITapGesture 仅识别 UIImageView 边框上的点击

javascript - 带有数据的 Angular 提交表

javascript - bootstrap 模态 div 上的圆 Angular

ios - swift 用户界面 : Input Field Keyboard animation causing other views in tab view to animate

iphone - 我想跟踪谁通过 ios 访问网站的电话号码