can applescript do this?

i have a browser interface that i reference to collect data from my website. (first name, last, street addr.) i spend hours typing all the items displayed in the browser to a filemaker file that has the following similar fields:

first name: Joe

last name: dude

street: 77 apple rd

and i need to move this info over to filemaker pro 4.1 to fields of the same name. i tried and import from filemaker, but filemaker cannot see the browser interface fields. can an applescript be created to move the data and how?

new to all this.

Yes, applescript can!
Anyway, looking for the quickest way, if it is your website, is the data in a database (eg, mysql, or a flat text file cvs)?
If not, can we see a sample page, so we figure the best way to approach?

it is a secured admin section so i will email you a screen shot of the data i need to extract from the browser window.

the database on the website is MySql.

Then, couldn’t you dump the sql-db to a flat-cvs file, then import it from FM? (my knowledge of sql = null)
Anyway, it is more interesting the source-code of the related page, not a screenshot, so we can see if it uses frames, forms, etc…

here is the source code from the browser window that has all the data i want to import to Filemaker Pro…

Are you saying that you want the value-lists from the HTML code you posted (country names, etc)? Or, is it that you use that page to look up information, and you are saying you’d like to fill in the form, submit it, and read the results back into FileMaker?

If it is the former, you can copy and paste the country list, then use a script to strip out the HTML cruft.

If it is the latter, you could use AppleScript to fill out and submit the web form, then read the result. See my pages on this at http://www.danshockley.com/applescript.html. However, I would guess jj’s advice would be better. If you control the MySQL database that the web page uses to run the lookup, just save the data to a tab-separated text file.

i want to take the data. say, “bob”, out of the field that says first name in the bowser window and import it into filemaker. BUT if i can go both ways, great.

so i pull up my browser. look at my data on the website db and take that data and go browner window > filemaker.

if i can also find a way to go filemaker > browser window, cool. but intial qestion concerns looking this html page in browser on internet and extract the contents and put on office filemaker db.

am i making sense? sorry if i’m not.

For quickness’ sake:

  1. 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”.

  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.

  1. 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…

Ooops! :oops: Just noticed that we are in the “OS” forum… You may use IE as your browser instead of Safari and “URL Access Scripting” to download & read the web pages instead of “curl”.
You can find several examples in this forum, just use the “Search” button!