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");
精彩评论