如何在 HTML 文档中找到一个数字然后用作 NSString?

发布于 2024-12-08 11:41:02 字数 1653 浏览 0 评论 0原文

在 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>

谢谢。

In UIWebView, how can I find a number (there's no other numbers or text on the page, just one number in the centre) and then use that as an NSString to make a UILabel show that number?

EDIT: The code of the webpage (around the number):

<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>

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

雨的味道风的声音 2024-12-15 11:41:02

如果您正在解析的 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 进行解析,但这是一个相当重量级的解决方案。

If the HTML that you are parsing always stays the same (except your number, obviously) you could use something like this:

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];

You can than parse the yourNumber however you like.

If, on the other hand, the HTML will differ significantly, I would use the MWFeedParser to parse, but this is a rather heavyweight solution.

乙白 2024-12-15 11:41:02

这应该有效:

NSString *content = [webView stringByEvaluatingJavaScriptFromString:@"document.body.innerHTML;"];

UILabel *label = ...;

[label setText:content];

This should work:

NSString *content = [webView stringByEvaluatingJavaScriptFromString:@"document.body.innerHTML;"];

UILabel *label = ...;

[label setText:content];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文