解决商品详情页面加载标签语言的方法
Posted zhangyulin311
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了解决商品详情页面加载标签语言的方法相关的知识,希望对你有一定的参考价值。
服务器返回:<p><img src=\\"http:\\/\\/www.hebeishilian.com\\/ueditor\\/php\\/upload\\/image\\/20180103\\/1514960629377900.jpg\\" style=\\"\\" title=\\"1514960629377900.jpg\\"\\/><\\/p><p><img src=\\"http:\\/\\/www.hebeishilian.com\\/ueditor\\/php\\/upload\\/image\\/20180103\\/1514960629404582.jpg\\" style=\\"\\" title=\\"1514960629404582.jpg\\"\\/><\\/p><p><img src=\\"http:\\/\\/www.hebeishilian.com\\/ueditor\\/php\\/upload\\/image\\/20180103\\/1514960629174968.jpg\\" style=\\"\\" title=\\"1514960629174968.jpg\\"\\/><\\/p><p><img src=\\"http:\\/\\/www.hebeishilian.com\\/ueditor\\/php\\/upload\\/image\\/20180103\\/1514960629636950.jpg\\" style=\\"\\" title=\\"1514960629636950.jpg\\"\\/><\\/p><p><img src=\\"http:\\/\\/www.hebeishilian.com\\/ueditor\\/php\\/upload\\/image\\/20180103\\/1514960630282186.jpg\\" style=\\"\\" title=\\"1514960630282186.jpg\\"\\/><\\/p><p><img src=\\"http:\\/\\/www.hebeishilian.com\\/ueditor\\/php\\/upload\\/image\\/20180103\\/1514960630717838.jpg\\" style=\\"\\" title=\\"1514960630717838.jpg\\"\\/><\\/p><p><img src=\\"http:\\/\\/www.hebeishilian.com\\/ueditor\\/php\\/upload\\/image\\/20180103\\/1514960630260520.jpg\\" style=\\"\\" title=\\"1514960630260520.jpg\\"\\/><\\/p><p><img src=\\"http:\\/\\/www.hebeishilian.com\\/ueditor\\/php\\/upload\\/image\\/20180103\\/1514960630865574.jpg\\" style=\\"\\" title=\\"1514960630865574.jpg\\"\\/><\\/p><p><img src=\\"http:\\/\\/www.hebeishilian.com\\/ueditor\\/php\\/upload\\/image\\/20180103\\/1514960630604992.jpg\\" style=\\"\\" title=\\"1514960630604992.jpg\\"\\/><\\/p><p><img src=\\"http:\\/\\/www.hebeishilian.com\\/ueditor\\/php\\/upload\\/image\\/20180103\\/1514960630317413.jpg\\" style=\\"\\" title=\\"1514960630317413.jpg\\"\\/><\\/p><p><br\\/><\\/p>"
//首先添加js,把获取到的信息中的图片及字体设置成自己想要展示的模式
- (void)loadContent:(NSString *)str
NSString *htmlString = [NSString stringWithFormat:@"<html> \\n"
"<p> \\n"
"<style type='text/css'> \\n"
"body font-size:15px;\\n"
"</style> \\n"
"</p> \\n"
"<body>"
"<script type='text/javascript'>"
"window.onload = function()\\n"
"var $img = document.getElementsByTagName('img');\\n"
"for(var p in $img)\\n"
"$img[p].style.width = '100%%';\\n"
"$img[p].style.height ='auto'\\n"
"\\n"
""
"</script>%@"
"</body>"
"</html>",str];
dispatch_async(dispatch_get_main_queue(), ^
[self.webView loadHTMLString:htmlString baseURL:nil];
);
//在
webViewDidFinishLoad中用通知获取高度
- (void)webViewDidFinishLoad:(UIWebView *)webView
CGSize fittingSize = [webView sizeThatFits:CGSizeZero];
self.height = fittingSize.height;
if (fittingSize.width > SCREEN_SIZE.width)
CGSize fittingSize = [webView systemLayoutSizeFittingSize:CGSizeZero];
self.height = fittingSize.height;
[[NSNotificationCenter defaultCenter] postNotificationName:@"WEBVIEW_HEIGHT_LOAD" object:nil userInfo:nil];
else
webView.frame = CGRectMake(0, 0, fittingSize.width, fittingSize.height);
[[NSNotificationCenter defaultCenter] postNotificationName:@"WEBVIEW_HEIGHT" object:@@"height":[NSString stringWithFormat:@"%f",_height] userInfo:nil];
在详情的VC中获取这个高度,并赋值给全局变量,刷新
- (void)noti:(NSNotification *)sender
_heightDetail = [sender.object[@"height"] floatValue];
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^
NSIndexSet *indexSet=[[NSIndexSet alloc]initWithIndex:3];
[self.tableView reloadSections:indexSet withRowAnimation:UITableViewRowAnimationTop];
[self netWorkLoadding:NO];
);
以上是关于解决商品详情页面加载标签语言的方法的主要内容,如果未能解决你的问题,请参考以下文章
使用Python+Selenium获取淘宝商品详情页面数据 ajax加载怎么取
非框架, 纯原生JS “商品详情跳转到商品列表,并记录高度“ 的写法思路