Hi,
I am working on a search plug-in for bookpedia - please note that I am quite new to this - and have a problem when submitting searches which only produce one result. The website I am getting data from automatically redirects you to a detail-book page if a search only produces one result, but the plugin example automatically says that there are no results if the page is redirected.
I would like to use the redirected page to obtain data from, but I am completly stuck. How do I do this or where do I look for information on handling data from redirected sites?
I am using xcode
-tsoerensen
Bookpedia plugin help
Re: Bookpedia plugin help
Hi,
That a bit complicated one. But the trick is to look for something that is always on the details page and then look for the URL of the details and the title and store only that one results.
This will work with the existing code for resultNumber, but it will re download the details page. You might want to have an extra instance variable that you can set the entire "HTMLSource" to and in resultNumber you check to see if HTMLSource != nil and if so you use that as the string to get the results. You would then have to remember to make it nil when you trigger a new search as to not get stuck in with the same results.
That a bit complicated one. But the trick is to look for something that is always on the details page and then look for the URL of the details and the title and store only that one results.
Code: Select all
- (void)downloadComplete:(NSString *)HTMLSource {
if ([HTMLSource rangeOfString:@"Something unique in details"].location != NSNotFound) { // single result
NSString *title = [HTMLSource stringBetween:@">" and:@"<" startingFrom:@"class=\"header\""];
title = [title stringByCleaningHTML];
NSString *url = [HTMLSource stringBetween:@"/title/tt" and:@"/"];
if (title && url) {
[resultsURLs addObject:url];
[resultsTitles addObject:title];
}
}
else {
The regular looking for results
}
[delegate searchReturnedNumberOfResults:[resultsTitles count] sender:self];
}
Code: Select all
- (void)searchFor:(NSDictionary *)searchDict sender:(id)sender{
[singleResult release];
singleResult = nil;
....
}
- (void)downloadComplete:(NSString *)HTMLSource {
if ([HTMLSource rangeOfString:@"Something unique in details"].location != NSNotFound) { // single result
singleResult = [HTMLSource retain];
[resultsTitles addObject:@"Single Result"];
}
else {
...
}
}
- (NSDictionary *)resultNumber:(int)number {
if (singleResult != nil)
results = singleResult;
else
results = ... download URL details code
parse details
}
-
- Contributor
- Posts: 9
- Joined: Mon Jul 11, 2011 7:33 pm
Re: Bookpedia plugin help
Thanks for the solution to the problem, works like magic
But from time to time I get this errormessage when debugging:
Bookpedia[13758:a0f] Call stack: (
0 Pediabase 0xc0f89f7f -[NSException(NSExceptionExtensions) printStackTrace] + 100
1 Pediabase 0xc0f34859 -[MyControllerShared(ApplicationNotifications) exceptionHandler:shouldHandleException] + 126
2 ExceptionHandling 0x9028a260 -[NSExceptionHandler _handleException] + 1264
3 ExceptionHandling 0x90289d52 NSExceptionHandlerExceptionRaiser + 228
4 libobjc.A.dylib 0x9148b5a9 objc_exception_throw + 56
5 CoreFoundation 0x98b6b3f8 +[NSException raise:format:arguments:] + 136
6 CoreFoundation 0x98b6b36a +[NSException raise:format:] + 58
7 Foundation 0x97163867 -[NSString stringByAppendingString:] + 111
8 ArnoldBusck 0x027775a7 -[sample resultNumber:] + 108294
9 Pediabase 0xc0f1f2b3 -[MyControllerShared resultsFoundWithSite:numberOfResults:] + 700
10 ArnoldBusck 0x0275ce99 -[sample downloadComplete:] + 851
11 ArnoldBusck 0x02777d18 -[sample connectionDidFinishLoading:] + 359
12 Foundation 0x97183077 -[NSURLConnection(NSURLConnectionReallyInternal) sendDidFinishLoading] + 84
13 Foundation 0x97182fe8 _NSURLConnectionDidFinishLoading + 133
14 CFNetwork 0x91cda5bb _ZN19URLConnectionClient23_clientDidFinishLoadingEPNS_26ClientConnectionEventQueueE + 197
15 CFNetwork 0x91d52a74 _ZN19URLConnectionClient26ClientConnectionEventQueue33processAllEventsAndConsumePayloadEP20XConnectionEventInfoI12XClientEvent18XClientEventParamsEl + 306
16 CFNetwork 0x91cccae4 _ZN19URLConnectionClient13processEventsEv + 94
17 CFNetwork 0x91ccc987 _ZN17MultiplexerSource7performEv + 183
18 CoreFoundation 0x98ad645b __CFRunLoopDoSources0 + 1563
19 CoreFoundation 0x98ad3f1f __CFRunLoopRun + 1071
20 CoreFoundation 0x98ad33f4 CFRunLoopRunSpecific + 452
21 CoreFoundation 0x98ad3221 CFRunLoopRunInMode + 97
22 HIToolbox 0x94cd8e04 RunCurrentEventLoopInMode + 392
23 HIToolbox 0x94cd8bb9 ReceiveNextEventCommon + 354
24 HIToolbox 0x94cd8a3e BlockUntilNextEventMatchingListInMode + 81
25 AppKit 0x90a3f595 _DPSNextEvent + 847
26 AppKit 0x90a3edd6 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 156
27 AppKit 0x90a011f3 -[NSApplication run] + 821
28 AppKit 0x909f9289 NSApplicationMain + 574
29 Bookpedia 0x0000237b _start + 209
30 Bookpedia 0x000022a9 start + 41
)
2011-07-15 12:05:14.281 Bookpedia[13758:a0f] *** -[NSCFString stringByAppendingString:]: nil argument
I think it must be something to do with this piece of code, but not sure:
NSEnumerator *linksEnum = [[results stringsBetween:@"<h2><a href=\"/varekat" and:@"</h2>"] objectEnumerator];
NSString *nextLink;
while (nextLink = [linksEnum nextObject]) {
NSString *theURL = [nextLink stringBetween:@"alog" and:@"\""];
NSString *theTitle = [nextLink stringBetween:@">" and:@"</a>"];
theTitle = [theTitle stringByCleaningHTML];
if (theURL && theTitle) {
theURL = [@"www.arnoldbusck.dk/varekatalog" stringByAppendingString:theURL];
[resultsTitle addObject:[theTitle substringFromIndex:0]];
[resultsURL addObject:theURL];
Any help would be appreciated
Thanks in advance
But from time to time I get this errormessage when debugging:
Bookpedia[13758:a0f] Call stack: (
0 Pediabase 0xc0f89f7f -[NSException(NSExceptionExtensions) printStackTrace] + 100
1 Pediabase 0xc0f34859 -[MyControllerShared(ApplicationNotifications) exceptionHandler:shouldHandleException] + 126
2 ExceptionHandling 0x9028a260 -[NSExceptionHandler _handleException] + 1264
3 ExceptionHandling 0x90289d52 NSExceptionHandlerExceptionRaiser + 228
4 libobjc.A.dylib 0x9148b5a9 objc_exception_throw + 56
5 CoreFoundation 0x98b6b3f8 +[NSException raise:format:arguments:] + 136
6 CoreFoundation 0x98b6b36a +[NSException raise:format:] + 58
7 Foundation 0x97163867 -[NSString stringByAppendingString:] + 111
8 ArnoldBusck 0x027775a7 -[sample resultNumber:] + 108294
9 Pediabase 0xc0f1f2b3 -[MyControllerShared resultsFoundWithSite:numberOfResults:] + 700
10 ArnoldBusck 0x0275ce99 -[sample downloadComplete:] + 851
11 ArnoldBusck 0x02777d18 -[sample connectionDidFinishLoading:] + 359
12 Foundation 0x97183077 -[NSURLConnection(NSURLConnectionReallyInternal) sendDidFinishLoading] + 84
13 Foundation 0x97182fe8 _NSURLConnectionDidFinishLoading + 133
14 CFNetwork 0x91cda5bb _ZN19URLConnectionClient23_clientDidFinishLoadingEPNS_26ClientConnectionEventQueueE + 197
15 CFNetwork 0x91d52a74 _ZN19URLConnectionClient26ClientConnectionEventQueue33processAllEventsAndConsumePayloadEP20XConnectionEventInfoI12XClientEvent18XClientEventParamsEl + 306
16 CFNetwork 0x91cccae4 _ZN19URLConnectionClient13processEventsEv + 94
17 CFNetwork 0x91ccc987 _ZN17MultiplexerSource7performEv + 183
18 CoreFoundation 0x98ad645b __CFRunLoopDoSources0 + 1563
19 CoreFoundation 0x98ad3f1f __CFRunLoopRun + 1071
20 CoreFoundation 0x98ad33f4 CFRunLoopRunSpecific + 452
21 CoreFoundation 0x98ad3221 CFRunLoopRunInMode + 97
22 HIToolbox 0x94cd8e04 RunCurrentEventLoopInMode + 392
23 HIToolbox 0x94cd8bb9 ReceiveNextEventCommon + 354
24 HIToolbox 0x94cd8a3e BlockUntilNextEventMatchingListInMode + 81
25 AppKit 0x90a3f595 _DPSNextEvent + 847
26 AppKit 0x90a3edd6 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 156
27 AppKit 0x90a011f3 -[NSApplication run] + 821
28 AppKit 0x909f9289 NSApplicationMain + 574
29 Bookpedia 0x0000237b _start + 209
30 Bookpedia 0x000022a9 start + 41
)
2011-07-15 12:05:14.281 Bookpedia[13758:a0f] *** -[NSCFString stringByAppendingString:]: nil argument
I think it must be something to do with this piece of code, but not sure:
NSEnumerator *linksEnum = [[results stringsBetween:@"<h2><a href=\"/varekat" and:@"</h2>"] objectEnumerator];
NSString *nextLink;
while (nextLink = [linksEnum nextObject]) {
NSString *theURL = [nextLink stringBetween:@"alog" and:@"\""];
NSString *theTitle = [nextLink stringBetween:@">" and:@"</a>"];
theTitle = [theTitle stringByCleaningHTML];
if (theURL && theTitle) {
theURL = [@"www.arnoldbusck.dk/varekatalog" stringByAppendingString:theURL];
[resultsTitle addObject:[theTitle substringFromIndex:0]];
[resultsURL addObject:theURL];
Any help would be appreciated
Thanks in advance
-
- Contributor
- Posts: 9
- Joined: Mon Jul 11, 2011 7:33 pm
Re: Bookpedia plugin help
WuuHuuu fiddled a bit about with i and now it works fine
For anyone interested in Danish (nordic) booksearch from ArnoldBusck.dk you can get and test the plugin here: http://files.me.com/tsoerensen/bbdxoe
*edit: the link
For anyone interested in Danish (nordic) booksearch from ArnoldBusck.dk you can get and test the plugin here: http://files.me.com/tsoerensen/bbdxoe
*edit: the link
Re: Bookpedia plugin help
Glad you where able to find the bug, it is for sure a "stringByAppendingString:" call in the code, but I would have guessed it was not the one mentioned above, as the error is that the string your appending is empty and not a string, yet the line before checks exactly for that issue.
The easiest thing to do for bugs is to add DVDpedia.app as a "custom executable" and launch with "Build-Debug" command. Add these two into your breakpoint window:
Now any time a bug happens Xcode will come up and point to the exact line where the exception occurred, no need to use search and find and figure out which line the bug is on.
Thank you for sharing that Danish plugin our Danish users will be delighted they been using only Saxo for the last few years.
Code: Select all
if (theURL && theTitle) { // theURL is not nil
theURL = [@"www.arnoldbusck.dk/varekatalog" stringByAppendingString:theURL];
Code: Select all
objc_exception_throw
-[NSException raise]
Thank you for sharing that Danish plugin our Danish users will be delighted they been using only Saxo for the last few years.
-
- Contributor
- Posts: 9
- Joined: Mon Jul 11, 2011 7:33 pm
Re: Bookpedia plugin help
I must admit that I were a bit out of my depth as this is the first time ever that I have played around with Objective-C and Cocao - but your help + the sample + and a swedish DVDpedia plugin was great in the immersion process
Anywho I would like for others to use/test the plugin, therefor my question is where to post it?
Currently it searches for:
Title
Author
Release (year only)
Price (eg 123,45 kr.)
Publisher
Binding
Genre (a bit weak!!)
Coverimage
Summary
Isbn/ean
Pages
Edition
Custom1 - original language
Custom3 - language
By default it just Does a keyword search
Might need tweeking on handling æ,ø,å
All best
Tsoerensen
Anywho I would like for others to use/test the plugin, therefor my question is where to post it?
Currently it searches for:
Title
Author
Release (year only)
Price (eg 123,45 kr.)
Publisher
Binding
Genre (a bit weak!!)
Coverimage
Summary
Isbn/ean
Pages
Edition
Custom1 - original language
Custom3 - language
By default it just Does a keyword search
Might need tweeking on handling æ,ø,å
All best
Tsoerensen