【问题标题】:Get the specific portion of the HTML Page using IPhone SDK?使用 iPhone SDK 获取 HTML 页面的特定部分?
【发布时间】:2012-11-10 16:28:33
【问题描述】:

在我的应用程序中,我有一个网页的 URL,我想通过识别 html 标签从该 URL(其 html 页面)中获取特定的部分/部分。

例如,我想根据 html 源代码获取 <div id="content"> to </div> 的部分。 这样我就可以将它保存在另一个文件中。

例如我的网址是

1) http://www.makepartsfast.com/2012/09/4337/more-3d-printing-in-metals-ex-one-introduces-the-m-flex-3d-printing-system/

2) http://www.windpowerengineering.com/policy/new-study-shows-the-benefits-of-wind-energy-in-kansas/

3) http://www.windpowerengineering.com/design/mechanical/bearings/podcast-for-windtech-2012-generator-maintenance/

所有这些 URL 都会打开文章 html 页面。但我只想显示 HTML 页面的主要内容

我也通过我的以下代码仅针对某些 URL 成功。

我的代码:

NSString *originalString = [NSString stringWithContentsOfURL:[NSURL URLWithString:@"http://www.windpowerengineering.com/uncategorized/how-superfinishing-boosts-component-reliability/"] encoding:NSUTF8StringEncoding error:nil];

NSScanner *scanner = [NSScanner scannerWithString:originalString];
    NSString *extractedString = nil;


    [scanner scanUpToString:@"<div id=\"content\">" intoString:nil];
    [scanner scanString:@"<div id=\"content\">" intoString:nil];



    [scanner scanUpToString:@"<div style=\"clear:both;\">" intoString:&extractedString];


    if (extractedString) 
    {
        // string was extracted
        NSLog(@"%@", extractedString);
    }   

但不同的页面可能有多个&lt;div style=\"clear:both;\"&gt; 标签。因此,当该方法遇到该标签时,它会显示我只显示该标签之前的内容。

建议现在,我想计算所有&lt;div&gt; 标签并尝试从该HTML 页面获取所有主要内容。但我对此感到困惑。

我该怎么做?

帮帮我!!

谢谢..

【问题讨论】:

    标签: iphone html objective-c ios xcode


    【解决方案1】:

    我使用了 AFFeedParsing 方法。因为所有文章都是提要。您可以在

    上找到示例代码
    1. cocoacontrols

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-10-30
      • 2012-11-09
      • 1970-01-01
      • 2014-01-04
      • 2014-12-23
      • 2014-05-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多