• 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: How to get the title as text of a html file
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to get the title as text of a html file


  • Subject: Re: How to get the title as text of a html file
  • From: has <email@hidden>
  • Date: Fri, 1 Mar 2002 14:02:06 +0000

Victor Yee wrote:

>This handler will return the title after it's found. Otherwise, it'll error
>after searching the first 20 tags or until eof, whichever comes first.
>
>The limit of 20 is arbitrary and can be changed in the loop, but I think
>20 is a
>reasonable limitation (note that the 20 includes close tags). Of course,
>you can
>set your own limit (or no limit, aka eof).
>
>Note that it isn't entirely thorough in that it doesn't verify the close tag.

Doesn't really need to - the &gt;title&lt; element *must* be properly closed
anyway (otherwise the page is terminally broken).

Below is a slightly modified version of your handler. Strictly speaking,
the &gt;title&lt; element could appear anywhere in the head, so rather than
checking an arbitrary number of tags (20) it's better to keep looking to
the end of the head element. I've also allowed for the possibility of the
title element having attributes by using "begins with" rather than "is" for
the comparison.

======================================================================

on parseHtmlTitle(thisFile)
open for access file thisFile
set fileRef to result
try
ignoring case
repeat
read fileRef until "<"
read fileRef before ">"
if result begins with "title" then
read fileRef before "<"
set thisTitle to result
close access fileRef
return thisTitle
else if result is "/head" then
error "<TITLE> tag not found."
end if
end repeat
end ignoring
on error errMsg number errNum
close access fileRef
if errNum is -39 then
error "EOF. <TITLE> tag not found." number errNum
else
error errMsg number errNum
end if
end try
end parseHtmlTitle

======================================================================

HTH

has
_______________________________________________
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.

  • Prev by Date: Re: URL Access Scripting?
  • Next by Date: Re: Wind Chill (corrected & full)
  • Previous by thread: Re: How to get the title as text of a html file
  • Next by thread: Re: How to get the title as text of a html file
  • Index(es):
    • Date
    • Thread