Ios从html获取href标签

时间:2015-06-12 05:58:51

标签: html ios

我有一个html代码,我想从中获取<a href>代码值。

<span class="meta">
    <span itemprop="author" class="meta-author"> 
        <a href="http://beta.morningnewsusa.com/author/kmnaing" title="Posts by James Kong" rel="author">
            James Kong
        </a>
    </span>
</span>

现在我正在使用以下代码返回nil: -

NSString *imgURL = [
    NSString stringWithFormat:@"document.elementFromPoint(%f, %f).parentNode.href",  
    touchPoint.x, touchPoint.y
]; 
NSString *urlToSave = [
    _webView1  stringByEvaluatingJavaScriptFromString:imgURL
];

1 个答案:

答案 0 :(得分:0)

最后这段代码对我有用: -

NSString *imgURL = [
    NSString stringWithFormat:@"document.elementFromPoint(%f, %f).href",
    touchPoint.x,
    touchPoint.y
];