extract specific text out of htm / text file into filemaker

To all who might help

I’m a newbie on applescript,

idea : extract specific information out of html file / code store it into
respective field in database.

ex. fruit search engine web-page

1 you introduce what you seeking ex. apple

2 executing search

3 getting result page (with for ex fields like:
color,size, price, etc…)

the results you see it in the result page in the browser, now to extract the results I assume you have to use html source code

4 defining position of every field ( by the text
that is in front and behind the field. ex
color,that means the expession in the source
code that is in front of the color and behind)

5 the so identified color store it in color field
of your database and proceed with the next


THX for having a look I hope it’s more or less clear :slight_smile:



You need three tools and a little of effort: AppleScript installed ( :lol: ), URL Access Scripting & Filemaker.
Also, you can substitute URL Access Scripting for a web browser, but theorically you don’t need it.
Step 1. “Download” the web page with results from a search query. Look at URL Access Scripting dictionary. You should see a command called “download” with several parameters. You can download an URL such as “http://www.google.com/search?hl=en&ie=ISO-8859-1&q=apple”, which will give you a HTML page with the results of searching “apple” at Google.
Step 2. “Read” this web page. You can find some useful commands within “Standard Additions”’ terminology: open for access, read, close access.
Step 3. Extract the info you’re looking for from this text and enclose it into variables, for later use.
Step 4. Put this info within your FM db (this is easy; look at FM’s dictionary).

If you need some detailed info about any particular question, this is your site!

AppleScript defines several properties & command to work with strings. You can extract from a given text its “word 1” or its “character 6”, or a bunch of text “characters 1 thru 8”.
Also, you can determine the position of a given string into a long text offset of “text” in “Hello, text!” (which will return “8”… character 8 is “t”).
So, if we call “html_code” to the text you’ve posted:

set x to (offset of "Maturity date(*)</strong></td> 
<td class='secdb'>" in html_code) + 50
set y to (offset of " </td> 
<tr height="3">" in html_code) - 1

set maturity_date to text from character x of html_code to character y of html_code
--> "16 May 2010"

I sum 50 to x because I don’t want include that string into my calculation. 50 is the length of “Maturity date(*)</str…”.
And I rest 1 to y because I don’t want include “&” into the string…

Now, set the value of a FM’s field may be easy:

tell application "FileMaker Pro"
	set cell "maturity" of record 54 of database 1 to maturity_date
end tell


thx a lot

I think I follow your idea, I try the script
and I’m sure I made small mistake it says
the variable html_code is not defined.
How can I tell the script to find the string in a
specific html file in a specific folder ??

thx for all help


You should read the file. If it’s located, eg, at “HD:Web Pages:file.html”:

set html_file to alias "HD:Web Pages:file.html"
set file_ref to (open for access html_file)
set html_code to (read file_ref)
close access file_ref

Now, the html code (simple text) is enclosed into the variable “html_code”, and you can manipulate it.

me again

I’m using os x and the hd name is “mac - osx” and the name of the file “test.html”
I don’t know the syntax to use test.html in your last ex.

set html_file to alias “mac - osx:test.html”
set file_ref to (open for access html_file)
set html_code to (read file_ref)
close access file_ref

and I get all time an error


Where is located “test.html”? If it is at root level, your alias will be:

alias "mac - osx:test.html".

If not, you can select the file in the Finder and run this code:

tell application "Finder"
	selection as alias
end tell

And it will return the path to the file.
Also, if you work with any script editor different than Apple’s “Script Editor” (Smile, freeware, http://www.satimage.fr/software/en/softx.html; or Script Debugger, shareware, http://www.latenightsw.com/) you can drag & drop any file into a script window and the path will be automatically placed at the window…