我已经在我的项目中实现了 HTMLParser。我正在连接到我的手机运营商的计费网站,我需要解析不同的变量。
来自HTML内容
如果用户名和密码不正确,我需要一个标签来指示我并向用户显示警报。
NSArray *spanNodes = [bodyNode findChildTags:@"div"];
for (HTMLNode *spanNode in spanNodes) {
if ([[spanNode getAttributeNamed:@"class"] isEqualToString:@"notification-item notification-item-error"]) {
//Above my tag
[self alertMessageLogin];
NSLog(@"%@", [spanNode rawContents]); //Answer to second question
}
else {
NSlog(@"You are not logged in");
}
}
但是如果我在这段代码中添加了 else ,那么我需要检查 else 没有标签“notification-item notification-item-error”,所以给我看另一个视图。
在我的情况下,之后if
,我的代码将出于else
某种原因,所以我的代码认为if
条件为假并进入else
条件。但没有else
一切工作正常。这是我的日志else
。我不知道,为什么会打印几个“您已登录”?
我该如何解决这个问题?
2013-04-09 23:48:50.828 GolanTelecom[90143:c07] You are logged in
2013-04-09 23:48:50.830 GolanTelecom[90143:c07] You are logged in
2013-04-09 23:48:50.830 GolanTelecom[90143:c07] You are logged in
2013-04-09 23:48:50.830 GolanTelecom[90143:c07] You are logged in
2013-04-09 23:48:50.830 GolanTelecom[90143:c07] You are logged in
2013-04-09 23:48:50.831 GolanTelecom[90143:c07] You are logged in
2013-04-09 23:48:50.831 GolanTelecom[90143:c07] You are logged in
2013-04-09 23:48:50.831 GolanTelecom[90143:c07] You are logged in
2013-04-09 23:48:50.832 GolanTelecom[90143:c07] You are logged in
2013-04-09 23:48:50.832 GolanTelecom[90143:c07] You are logged in
2013-04-09 23:48:50.832 GolanTelecom[90143:c07] You are logged in
2013-04-09 23:48:50.833 GolanTelecom[90143:c07] You are logged in
2013-04-09 23:48:50.833 GolanTelecom[90143:c07] You are logged in
2013-04-09 23:48:50.833 GolanTelecom[90143:c07] You are logged in
2013-04-09 23:48:50.833 GolanTelecom[90143:c07] You are logged in
2013-04-09 23:48:50.834 GolanTelecom[90143:c07] You are logged in
2013-04-09 23:48:50.834 GolanTelecom[90143:c07] <div
class="notification-item notification-item-error"><div
class="notification-item-inner"><span
class="notification-content">???? ???? ?? ?????
??????</span></div></div> 2013-04-09 23:48:50.834
GolanTelecom[90143:c07] You are logged in 2013-04-09 23:48:50.835
GolanTelecom[90143:c07] You are logged in 2013-04-09 23:48:50.835
GolanTelecom[90143:c07] You are logged in 2013-04-09 23:48:50.835
GolanTelecom[90143:c07] You are logged in