在UIWebView中,我如何找到一个数字(页面上没有其他数字或文本,中间只有一个数字),然后将其用作NSString以使UILabel显示该数字?
编辑:网页代码(数字周围):
<div style="width: auto; padding:0px; height: auto;" class="ajax_qe" id="ajax_qe_200139_1"><iframe id='qe_logFrm_200139'
instance='1' class='frog3_enabled' style='display:none;'></iframe><div id="np_200139-1" class="brick s_php_eval" type="PHP"
dfid=""></div><div id="np_200139-2" class="brick s_addspace" type="Blank Space" dfid=""><div style="overflow: hidden; font-size:
0px; width: 100%; height: 5px; "></div></div><div id="np_200139-3" class="brick s_text" type="Text and Pictures" dfid=""><table
border=0 cellspacing=0 cellpadding=0 width='100%' class='alt_200139'><tr><td><P align=center><STRONG><FONT color=#5dd228
size=4>8</FONT></STRONG></P></td></tr></table></div><div class="page_marker" id="edit_link_200139_1" style="display: block;
width:; height:;"><a class="edit_link rootpage" style="display: block;" href="#" onclick="qe_login(200139, 0); return false;"
title="Edit this Page"><img src="/sysimages/editfullpage.gif" style="border: none;" /></a></div><div style="clear: both"></div>
</div><div id="r3603" style="position: relative;text-align: center;width: 100%;"><div style="z-index: 11;position:
static;display: inline;">Powered by <a class=ROLLOVER href="http://www.frogteacher.com/" target=_blank><B>Frog</B></A></div>
感谢。
答案 0 :(得分:1)
这应该有效:
NSString *content = [webView stringByEvaluatingJavaScriptFromString:@"document.body.innerHTML;"];
UILabel *label = ...;
[label setText:content];
答案 1 :(得分:1)
如果您要解析的HTML总是保持不变(显然除了您的号码),您可以使用以下内容:
NSString* yourNumber;
NSScanner *htmlScanner = [NSScanner scannerWithString:yourHtmlString];
[htmlScanner scanUpToString:@"<FONT color=#5dd228 size=4>" intoString:NULL];
[htmlScanner scanString:@"<FONT color=#5dd228 size=4>" intoString:NULL];
[htmlScanner scanUpToString:@"</FONT>" intoString:&yourNumber];
您可以随心所欲地解析yourNumber
。
另一方面,如果HTML显着不同,我会使用MWFeedParser进行解析,但这是一个相当重要的解决方案。