For quickness’ sake:
- Through the browser:
set x to "x=document.forms[0];
finalInfo='';
for (i=0;i<x.length;i++){
if (x.elements[i].type == 'select-one') {
xt = x.elements[i].options[x.elements[i].selectedIndex].text;
elementInfo=xt;
} else {
elementInfo = x.elements[i].value;
}
finalInfo += '\r' + elementInfo;
}
finalInfo"
tell application "Safari"
set currentDocInfo to rest of paragraphs of (do JavaScript x in document 1)
end tell
To use IE instead, change “do JavaScript” with “do script” and delete “in document 1”.
- Faceless, quickest:
set theFlags to {"name="customers_firstname" value="", "name="customers_lastname" value="", "customers_email_address" value="", "name="entry_company" value="", "entry_street_address" value="", "entry_suburb" value="", "entry_postcode" value="", "entry_city" value="", "SELECTED>", "SELECTED>", "entry_state" value="", "customers_telephone" value="", "customers_fax" value="", "SELECTED>"}
set theFlags2 to {""", """, """, """, """, """, """, """, "</option>", "</option>", """, """, """, "</option>"}
set webPage to "https://secure.server.com/customer.php?id=477"
set htmlText to (do shell script "curl " & quoted form of webPage)
set finalList to {}
repeat with i from 1 to theFlags's length
try
set stuffStart to theFlags's item i
set flag1 to (offset of stuffStart in htmlText) + (stuffStart's length)
if flag1 = (stuffStart's length) then error
set htmlText to text flag1 thru -1 of htmlText
set stuffEnd to theFlags2's item i
set flag2 to (offset of stuffEnd in htmlText) - 1
set finalList's end to text 1 thru flag2 of htmlText
set htmlText to text flag2 thru -1 of htmlText
on error
set finalList's end to ""
end try
end repeat
finalList
Please, edit the “webPage” variable.
- Five-minutes solution: if you can export the sql db to a tab-delimited file, do it and import it from FM!
These two scripts will return a list of items found in the form. The first one (using the browser) will return also the “hidden” fields. You can adjust the second routine to return, too, hidden fields.
So, if you know what pages you call, you can use this (NOTE: SAMPLE CODE):
property theFlags : {"name="customers_firstname" value="", "name="customers_lastname" value="", "customers_email_address" value="", "name="entry_company" value="", "entry_street_address" value="", "entry_suburb" value="", "entry_postcode" value="", "entry_city" value="", "SELECTED>", "SELECTED>", "entry_state" value="", "customers_telephone" value="", "customers_fax" value="", "SELECTED>"}
property theFlags2 : {""", """, """, """, """, """, """, """, "</option>", "</option>", """, """, """, "</option>"}
set baseWebPage to "https://secure.server.com/customer.php?id="
set fileToImportLaterIntoFileMaker to (path to desktop as text) & "file.txt"
repeat with i from 1 to 1500
set theWebPage to baseWebPage & (i as string)
--> eg, "https://secure.server.com/customer.php?id=1"
set allEntries to getRecordEntries(do shell script "curl " & theWebPage)
set AppleScript's text item delimiters to tab
set allEntries to "" & allEntries
set AppleScript's text item delimiters to {""}
--> eg, "bob smith bob@smith.com..."
--> write the info to a plain text file
set openFile to (open for access file fileToImportLaterIntoFileMaker with write permission)
write allEntries & return to openFile starting at eof
close access openFile
end repeat
display dialog "1500 records in my plain-text DB!" & return & return & "I'm ready to switch to FM and import it manually!" with icon note
to getRecordEntries(htmlText)
set finalList to {}
repeat with i from 1 to theFlags's length
try
set stuffStart to theFlags's item i
set flag1 to (offset of stuffStart in htmlText) + (stuffStart's length)
if flag1 = (stuffStart's length) then error
set htmlText to text flag1 thru -1 of htmlText
set stuffEnd to theFlags2's item i
set flag2 to (offset of stuffEnd in htmlText) - 1
set finalList's end to text 1 thru flag2 of htmlText
set htmlText to text flag2 thru -1 of htmlText
on error
set finalList's end to ""
end try
end repeat
return finalList
end getRecordEntries
Most probably, you will need some adjustments for “curl”, such as add your login/password: “https://user:password@secure.server.com/page.html”. If this doesn’t work for you, type “man curl” in the Terminal for extra options…