parsing form data from html source...
parsing form data from html source...
- Subject: parsing form data from html source...
- From: Matt Holland <email@hidden>
- Date: Fri, 20 Apr 2001 10:49:41 -0700
- Organization: FCB
Hi all,
I'm working on a script to retrieve information from a PostgreSQL
generated web page, and place it in a Filemaker Pro database. As I am
completely unfamiliar with SQL or how Filemaker Pro can pull information
from it, I decided to use Applescript.
So far I've got a large messy script that uses a repeat loop,
incrementing the URL's post argument and then running the source of the
returned page through Akua's Parse ML and Acme Trim to get the form data
names and values. It's messy and doesn't always work right. My question,
is whether any of you know of a scripting addition command that will
return a list of records from the tags in HTML source such as
<input name="serial" value="QT1104Z2K6B" size=20><br></td>
and
<SELECT name="category"><option value=""><option
value="accountservice">accountservice<option value="admin"
selected>admin
returns {name:"QT1104Z2K6B", category:"admin"}
Alternatively, if any of you know of any online resources explaining how
to retrieve data from PostgreSQL to FileMaker, I'd appreciate the links.
Here's the script I have so far. Thanks in advance for any help.
tell application "FileMaker Pro"
activate
open file "Mac OS 9.1:hardware.fp5"
end tell
repeat with i from 1 to 237
set HID to i
if i < 10 then
tell application "Internet Explorer"
Activate
OpenURL "
http://my.intranetpage.com/db/hardware/show?hid=00" & HID
set theSource to ((GetSource) as string)
end tell
else if ((i < 100) and (i > 10)) then
tell application "Internet Explorer"
Activate
OpenURL "
http://my.intranetpage.com/db/hardware/show?hid=0" & HID
set theSource to ((GetSource) as string)
end tell
else
tell application "Internet Explorer"
Activate
OpenURL "
http://my.intranetpage.com/db/hardware/show?hid=" & HID
set theSource to ((GetSource) as string)
end tell
end if
set htmlList to (parse ML theSource)
if (i = 2) then
log htmlList
end if
set type to item (offset in list htmlList of "input name=\"type\"" case
insensitive without exact match) of htmlList
set type to (trim "<input name=\"type\" value=\"" off type from front
side)
set type to (trim "\" size=40>" off type from back side)
set serial to item (offset in list htmlList of "input name=\"serial\""
case insensitive without exact match) of htmlList
set serial to (trim "<input name=\"serial\" value=\"" off serial from
front side)
set serial to (trim "\" size=20>" off serial from back side)
set theNote to item (offset in list htmlList of "input name=\"note\""
case insensitive without exact match) of htmlList
set theNote to (trim "<input name=\"note\" value=\"" off theNote from
front side)
set theNote to (trim "\" size=40>" off theNote from back side)
set theCat to item (offset in list htmlList of "selected>" case
insensitive without exact match) of htmlList
set theCat to (trim "<option value=\"" off theCat from front side)
set theCat to (trim "\" selected>" off theCat from back side)
offset in list htmlList of "<SELECT name=\"user\">"
count items in htmlList
set htmlList to (items 294 thru (length of htmlList) of htmlList) as
list
set theName to item (offset in list htmlList of "selected>" case
insensitive without exact match) of htmlList
set theName to (trim "<option value=\"" off theName from front side)
set theName to (trim "\" selected>" off theName from back side)
tell application "FileMaker Pro"
if i < 10 then
set cellValue of cell "HID" of record i to "00" & HID
else if ((i < 100) and (i > 10)) then
set cellValue of cell "HID" of record i to "0" & HID
else
set cellValue of cell "HID" of record i to HID
end if
set cellValue of cell "Type" of record i to type
set cellValue of cell "Serial" of record i to serial
set cellValue of cell "Category" of record i to theCat
set cellValue of cell "User" of record i to theName
set cellValue of cell "Note" of record i to theNote
create new record
end tell
end repeat
--
Matt Holland
Helpdesk Monkey
FCB Worldwide, Seattle