• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Was: "+" and "-" are numbers. IS: URL parsing
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Was: "+" and "-" are numbers. IS: URL parsing


  • Subject: Re: Was: "+" and "-" are numbers. IS: URL parsing
  • From: has <email@hidden>
  • Date: Mon, 5 Aug 2002 15:14:22 +0100

ThePPCGod wrote:

> you might want to take a look at NetScape Navigator 4.6.x/4.7.x, which
>have an AS command to extract the base URL out of a longer URL... I don't
>know if it passes back just the site, or the specific page stripped of
>additional database info, but it might be worth a gander.

NS4: undisputed king of bad browsers. Wouldn't touch it with a 40 ft
pole:p. That said, I do keep a copy around for testing purposes. Not sure
what function you're referring to, however. There's a 'parse anchor'
command, but that's for resolving relative paths (I've already written a
vanilla function for this; it's pretty simple really).


Writing a vanilla routine to extract a base URL (by which I assume you're
meaning protocol + domain [plus username and password, if any]; do correct
me if I'm wrong) should be pretty trivial; something like:

on extractBaseURL(theURL)
try
set oldTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to "/"
if theURL's text 1 thru word 2 contains "://" then
set baseURL to theURL's text 1 thru text item 3 & "/"
else
set baseURL to theURL's text item 1 & "/"
end if
set AppleScript's text item delimiters to oldTID
on error eMsg number eNum
error "Couldn't extract base URL: " & eMsg number eNum
end try
return baseURL
end extractBaseURL

set theURL to "ftp://ftp.mozilla.org/pub/chimera/releases/chimera-0.4.dmg.gz";
extractBaseURL(theURL)
--> "ftp://ftp.mozilla.org/";

[I can't absolutely vouch for the above, since I'm not an expert on URL
structure (anyone see if I've missed anything?). Not a very good name
either, I suspect... any webheads have better suggestions?]

This is all much simpler than the pulling of URLs from a larger string that
also contains non-URL text, mind you, which is what I assume Arthur was
asking about (though I may be mistaken... the original question was pretty
vague).

has

--
(My email address has changed from <email@hidden> to
<email@hidden>. Please update your address books accordingly.)
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: Was: "+" and "-" are numbers. IS: URL parsing
      • From: Paul Berkowitz <email@hidden>
References: 
 >Was: "+" and "-" are numbers. IS: URL parsing (From: email@hidden)

  • Prev by Date: Re: Print in TextEdit
  • Next by Date: Re: Scripting "Startup Disk"
  • Previous by thread: Was: "+" and "-" are numbers. IS: URL parsing
  • Next by thread: Re: Was: "+" and "-" are numbers. IS: URL parsing
  • Index(es):
    • Date
    • Thread