开发者

using stringByEvaluatingJavaScriptFromString to extract the src of an img then assigning the url to a NSString OR NSURL

开发者 https://www.devze.com 2023-04-04 22:49 出处:网络
I\'m using a WebView in my cocoa application, I would like to extract an image\'s url from the WebView.

I'm using a WebView in my cocoa application, I would like to extract an image's url from the WebView.

I've been trying to use stringByEvaluatingJavaScriptFromString to extract it with no avail.

NSStrin开发者_高级运维g *imageURLString = [webView stringByEvaluatingJavaScriptFromString:@"$('#id1.class1.img').attr('src');"];

#id1 and .class1 are just place holders, the structure of the html looks like this

<ol id="id1">
   <div class="class1">
      <img src="url.jpg">

I would like to get the url as string and then turn it into NSURL to use with NSData, however, if I can get NSURL straight from the javascript, that's even better.


Thought I'd make this an actual answer since no one else left any. The right JavaScript for this is

$('#id1').find('.class1').find('img').attr("src");
0

精彩评论

暂无评论...
验证码 换一张
取 消