why is nsscanner giving me an extra result?
why is nsscanner giving me an extra result?
- Subject: why is nsscanner giving me an extra result?
- From: Michael Hanna <email@hidden>
- Date: Sun, 23 Jan 2005 14:51:37 -0500
I'm parsing web results with this method, but I find that the NSScanner
is giving me an extra result, that is, in this example instance, it
should find only one set of data rather than two. The extra item it
creates makes the artistName and the songName the same, which is really
odd. It seems like it's staying in the while-loop one more iteration
than I expect it to.....
any ideas what I'm assuming wrongly here?
Michael
- (void)parseMXTabsSongs
{
NSScanner *scanner = [NSScanner localizedScannerWithString:[self
myRawWebResult]];
NSString *scanResult = nil;
NSString *artistStartTag = @"<font size=\"2\" color=\"CCCCCC\">";
NSString *artistEndTag = @"</a>";
NSString *urlStartTag = @"- <a href=\"";
NSString *urlEndTag = @"\"";
NSString *songStartTag = @">";
NSString *songEndTag = @"</font>";
//remove all objects from the songs array
[songs removeAllObjects];
//NSLog(@"[songs removeAllObjects];");
// scan up to the artist's name
while([scanner scanUpToString:artistStartTag intoString:nil])
{
// skip over the artiststarttag
[scanner scanString:artistStartTag intoString:nil];
// found artist name, store it
[scanner scanUpToString:artistEndTag intoString:&scanResult];
//NSLog(@"scanResult %@", scanResult);
if(scanResult != nil)
{
//NSLog(@"if(scanResult)");
TaoSong *newSong = [[TaoSong alloc] init];
NSLog(@"scanResult artist %@", scanResult);
[newSong setArtistName:scanResult];
// scan up to the URL
[scanner scanUpToString:urlStartTag intoString:nil];
[scanner scanString:urlStartTag intoString:nil];
[scanner scanUpToString:urlEndTag intoString:&scanResult];
NSLog(@"scanResult URL %@", scanResult);
[newSong setTabLocation:[NSURL URLWithString:[NSString
stringWithFormat:@"http://mxtabs.net/%@",scanResult]]];
// scan up to the songStartTag
[scanner scanUpToString:songStartTag intoString:nil];
[scanner scanString:songStartTag intoString:nil];
[scanner scanUpToString:songEndTag intoString:&scanResult];
NSLog(@"scanResult song name %@", scanResult);
[newSong setSongName:scanResult];
// add these items to my songs array
[songs addObject:newSong];
[newSong release];
}
}
// off by one, not sure why, so just delete the last object
//if([songs count] > 1)
// [songs removeLastObject];
[self updateWebSearchTable];
NSLog(@"songs, %@", songs);
}
[ snip html code ]
1 Tab Found<br><br><font size="2"><a
href="songs.php?path=Guitar,r,1079,Rem"><font size="2"
color="CCCCCC">Rem</a> - <a
href="tab_versions.php?
path=Guitar,r,1079,Rem,How+The+West+Was+Won+And+Where+It+Got+Us+(Cho,1
0641">How The West Was Won And Where It Got Us
(Cho</font></a><br></font> <br>
</td>
</tr>
</table>
<table cellspacing="0" cellpadding="4"
align="center" width=700>
<tr>
<td height="2">
<b><font size="2"
color=#FFFFFF>Search
Again</font></b>
<table width="100%" border="0">
<tr bgcolor="#005B6A">
<td height=1>
<div align="right"></div>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td height="2"> <form method="post"
action="search_results.php">
<font size="2"><b>Find
<select name="search_in">
<option
selected>Bands</option>
<option>Songs</option>
</select>
Named </b></font>
<input name="search_text"
size="15" value="how the west was won">
<input type="SUBMIT"
value="Search!"
style="font-family:verdana; background-color:#C0C0C0;
color:#000000; font-size:10;" name="SUBMIT2">
<input type="hidden"
name="instrument" value="Guitar">
<br>
</div>
</form>
<br><br>
<font size=1>»<a
href="content.php?file=Mxtabs_Search"></a>Add Mxtabs Search to Your
Site</a>
</td>
</tr>
</table>
<br>
</td>
</tr>
<tr>
<td height="29" valign="top" nowrap><div align="right"><img
src="images/silverbar.gif" width="782" height="29" vspace="10"><br>
<font size="1">Copyright 1999-2004 Mxtabs | <a
href="content.php?file=Contact_Us">Contact</a> | <a
href="content.php?file=Advertise">Advertise</a> | <a
href="content.php?file=FAQ">FAQ</a></font>
</div></td>
</tr>
</table></HTML>
2005-01-23 14:40:54.885 GuitarPrompter[15944] scanResult artist Rem
2005-01-23 14:40:54.885 GuitarPrompter[15944] scanResult URL
tab_versions.php?
path=Guitar,r,1079,Rem,How+The+West+Was+Won+And+Where+It+Got+Us+(Cho,1
0641
2005-01-23 14:40:54.885 GuitarPrompter[15944] scanResult song name How
The West Was Won And Where It Got Us (Cho
2005-01-23 14:40:54.886 GuitarPrompter[15944] scanResult artist How The
West Was Won And Where It Got Us (Cho
2005-01-23 14:40:54.886 GuitarPrompter[15944] scanResult URL How The
West Was Won And Where It Got Us (Cho
2005-01-23 14:40:54.886 GuitarPrompter[15944] scanResult song name How
The West Was Won And Where It Got Us (Cho
2005-01-23 14:40:54.886 GuitarPrompter[15944] songs, <CFArray 0x301350
[0xa01900e0]>{type = mutable-small, count = 2, values = (
0 : <TaoSong: 0x3e6f40>
1 : <TaoSong: 0x3e6f50>
)}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden