[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] https request ...



At 17.16 +0100 2000.03.07, Carl Johan Berglund wrote:
>At 13.12 -0500 0-03-03, schinder@pobox.com wrote:
>>2) use an AppleEvent to ask a browser to do it for you.    How you get the
>>information out of the browser back to your script I don't know.
>
>One way is to instruct the browser to save things like the one you're
>getting as a file. Then Perl can go look in the download folder and
>read the file. I'm using that technique to get some log files on a
>remote server. If you're getting an HTML file, you don't want to have
>your browser saving them as files, but you can still ask it to do it
>for the duration of this. Maybe you can even set and re-set in using
>an Apple Event.

I am not sure what you mean about not saving them as files and setting and
re-setting ... but here is a simple method for getting contents of docs
with Mac::Glue:

  #!perl -w
  use File::Spec::Functions;
  use Mac::Glue;
  my($file, $text, $n);

  $file = catfile($ENV{TMPDIR}, "pause.html");
  $n = new Mac::Glue 'Netscape Communicator';
  $n->geturl('https://pause.kbx.de/', to => $file);

  sleep 10;  # set to reasonable value, waiting until file is saved

  { local($/, *F);
    open F, "< $file" or die "Can't open $file: $!";
    ($text = <F>) =~ s/\015?\012/\n/g;
  }

  print $text;


The only real problem with this is you don't know for sure when the
downloading is done.  If you want to do user interaction, you can do
(instead of a sleep):

  print "Hit <return> when download is complete:"; <>;

Netscape has a way to tell if a window is busy or whatever, but the dialog
used for saving URLs to files doesn't do that.

It would be "better" if someone could build OpenSSL and Net::SSL or
whatever ... I looked at it and my head hurt.  :)

-- 
Chris Nandor          mailto:pudge@pobox.com         http://pudge.net/
%PGPKey = ('B76E72AD', [1024, '0824090B CE73CA10  1FF77F13 8180B6B6'])

# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org