Note that there are some explanatory texts on larger screens.

plurals
  1. POImport Bookmarks from html file
    primarykey
    data
    text
    <p>Im trying to add a import bookmarks function to my app. I have some of it but it will just extract all URLs and titles.</p> <pre><code>- (NSArray *)urlsInHTML:(NSString *)html { NSError *error; NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"(?&lt;=href=\").*?(?=\")" options:NSRegularExpressionCaseInsensitive error:&amp;error]; NSArray *arrayOfAllMatches = [regex matchesInString:html options:0 range:NSMakeRange(0, [html length])]; NSMutableArray *arrayOfURLs = [[NSMutableArray alloc] init]; for (NSTextCheckingResult *match in arrayOfAllMatches) { NSString* substringForMatch = [html substringWithRange:match.range]; NSLog(@"Extracted URL: %@",substringForMatch); [arrayOfURLs addObject:substringForMatch]; } // return non-mutable version of the array return [NSArray arrayWithArray:arrayOfURLs]; } - (NSArray *)titlesOfTagsInHTML:(NSString *)html { NSError *error; NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"(?&lt;=\"\\&gt;)(.*?)(?=\\&lt;\\/)" options:NSRegularExpressionCaseInsensitive error:&amp;error]; NSArray *arrayOfAllMatches = [regex matchesInString:html options:0 range:NSMakeRange(0, [html length])]; NSMutableArray *arrayOfURLs = [[NSMutableArray alloc] init]; for (NSTextCheckingResult *match in arrayOfAllMatches) { NSString* substringForMatch = [html substringWithRange:match.range]; NSLog(@"Extracted Title: %@",substringForMatch); [arrayOfURLs addObject:substringForMatch]; } // return non-mutable version of the array return [NSArray arrayWithArray:arrayOfURLs]; } - (IBAction)import { ProgressAlertView *progressAlert = [[ProgressAlertView alloc] initWithTitle:@"Crux" message:@"Importing Bookmarks..." delegate:self cancelButtonTitle:nil otherButtonTitles:nil]; [progressAlert show]; NSString *htmlString = [NSString stringWithContentsOfFile:importingBookmarkFilePath encoding:NSUTF8StringEncoding error:nil]; NSArray *urls = [self urlsInHTML:htmlString]; NSArray *titles = [self titlesOfTagsInHTML:htmlString]; //float progress = [[NSNumber numberWithInt:i] floatValue]/[[NSNumber numberWithInteger:[urls count]-1] floatValue]; for (int i=0; i&lt;[urls count]; i++) { Bookmark *importedBookmark = [[Bookmark alloc] init]; importedBookmark.url = urls[i]; importedBookmark.title = titles[i]; [[[BookmarkManager sharedInstance] bookmarks] addObject:importedBookmark]; [[BookmarkManager sharedInstance] saveBookmarks]; } } </code></pre> <p>But I cant find how to determine folders so i can keep theme exactly the way they were in the other browser. To see how safari exports them just go to file>export bookmarks and you can see the html file. It puts everything in a definition list with the folder titles. Using NSREgularExpression or other ways, how can i get each folder title, and everything in that folder?</p> <p>I have tried using NSXMLParser to parse the html, but it stops at the first definition list tag and fails.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload