Re: How to get the title as text of a html file
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: Victor Yee <email@hidden>
- Date: Thu, 28 Feb 2002 20:36:14 -0500
On Thu, 28 Feb 2002 19:06:35 -0500, Rob Jorgensen wrote,
>
Do you want the title which is within the HTML code? If so, I'll back
>
out and let some of the parsing experts take over.
They're all busy at the moment, so you'll have to settle for me :)
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. It
assumes that the html is valid.
on parseHtmlTitle(thisFile)
open for access file thisFile
set fileRef to result
try
ignoring case
repeat 20 times
read fileRef until "<"
read fileRef before ">"
if result is "title" then
read fileRef before "<"
set thisTitle to result
close access fileRef
return thisTitle
end if
end repeat
end ignoring
error "<TITLE> tag not found within parse limit."
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
_______________________________________________
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.