PDA

View Full Version : Applescript+Cocoa URL source stealing mania!


Coin
2005.03.11, 04:30 PM
I + My friend are writing a program with Applescript and Cocoa.
here is what happens
applescript calls a method with a parameter/argument that contains a URL

my cocoa program takes the URL loads it into a webview and gets the source code, then sends that back in a string varible

my cocoa program has control over one inteface object. a webView for loading the url then retriving the source

here is what i have so far.. its a mess

appControl.h


/* appControl */

#import <Cocoa/Cocoa.h>
#import <Foundation/Foundation.h>

@interface appControl : NSObject
{
IBOutlet id webView;
}

- (NSString *)Source;

- (void)getCode;
- (IBAction)loadCodeFromURL:(NSString)inString;
@end



appControl.m

#import "appControl.h"
#import <WebKit/WebKit.h>
#import <WebKit/WebView.h>
#import <WebKit/WebDocument.h>

@implementation NSApplication (ASKAFullScreen)

- (void)getCodeh
{
}


- (IBAction)loadCodeFromURL:(NSString *)inString
{


NSURL *URL = [NSURL URLWithString:inString];

[webView setFrameLoadDelegate:self];

WebFrame *mainFrame = [webView mainFrame];

[mainFrame loadRequest:[NSURLRequest requestWithURL:URL]];



WebFrame *mainFrame = [webView mainFrame];

id documentRepresentation = [[mainFrame dataSource] representation];

if ([documentRepresentation canProvideDocumentSource]){
[out setStringValue: [documentRepresentation documentSource]];
}
else {
// NSRunAlertPanel(@"Wait", @"Page not done loading", @"Ok", nil, nil);
}
}

- (NSString *)Source
{
return @"Test";
}

-(void)dealloc
{
[super dealloc];
}


@end


i really dont know how to do any of this...

grammars fixed?

ThemsAllTook
2005.03.11, 05:03 PM
This message is utterly incomprehensible. The "Preview Post" button is there for a reason. Please use it, read what you've written before posting it, and correct errors such as stopping in the middle of a sentence. :rolleyes:

- Alex Diener

Steven
2005.03.11, 08:11 PM
So what's the question? Does what you have work?

Coin
2005.03.12, 12:36 AM
The question is how should i do this...

it is going to reqire only ONE method so it can return a value back to applescript but its also going to require a delagate method that fires when the webView finishes loading. so im lost....

Duane
2005.03.12, 09:33 AM
not exactly answering your question, but couldn't you just get the source by saying...
NSString *source = [NSString stringWithContentsOfURL:[NSURL URLWithString:urlString]]; where urlString is the url?

Coin
2005.03.12, 03:20 PM
I dont see that in my code....

what we did before was have applescript push a button that used cocoa to load a webview

then it pushed a button that got the source of the web view if it failed it tried again

it repeated until it got the source code

and that works but its horribly innefficient

Duane
2005.03.12, 03:29 PM
I don't know much about applescript, but to get the source, you would do the section of code mentioned above.

Coin
2005.03.12, 04:02 PM
Wait


i thouhgt you said you COULDNT get it just by doing that, and that was how i got it before... misread what you said......thanks taht makes it a jilliontimes easier