从UIWebView获取IMG标记src为NSString

时间:2022-11-27 18:18:44

How can I get the src of images of the current page in the UIWebView and be able to use it as a string later?

如何在UIWebView中获取当前页面的src图像,以后能够将其用作字符串?

2 个解决方案

#1


1  

Do this:

做这个:

NSString *imgSrcValue = [self.webview stringByEvaluatingJavaScriptFromString:
                @"document.getElementByID('yourImgScrID').value"];

#2


0  

What you want to do is parse the HTML for tags into an array, then extract all the src links into a new array (do this to avoid including other src tags for things like scripts). Bear in mind that some may be ".../image.png" so you will have to convert them into "theWebsiteYouWere.com/browsing/atTheTime/.png"

你想要做的是将标签的HTML解析成一个数组,然后将所有的src链接提取到一个新的数组中(这样做是为了避免包含脚本之类的其他src标签)。请记住,有些可能是“... / image.png”,因此您必须将它们转换为“theWebsiteYouWere.com/browsing/atTheTime/.png”

#1


1  

Do this:

做这个:

NSString *imgSrcValue = [self.webview stringByEvaluatingJavaScriptFromString:
                @"document.getElementByID('yourImgScrID').value"];

#2


0  

What you want to do is parse the HTML for tags into an array, then extract all the src links into a new array (do this to avoid including other src tags for things like scripts). Bear in mind that some may be ".../image.png" so you will have to convert them into "theWebsiteYouWere.com/browsing/atTheTime/.png"

你想要做的是将标签的HTML解析成一个数组,然后将所有的src链接提取到一个新的数组中(这样做是为了避免包含脚本之类的其他src标签)。请记住,有些可能是“... / image.png”,因此您必须将它们转换为“theWebsiteYouWere.com/browsing/atTheTime/.png”