searching the source

I have the following source of a page only on errors and i would like to search the page for a unique word, then have an if that checks it.

I get the source with curl and at the moemnt i do use an if to do what i want but it doesnt really work

source code



<html>
<head>

</head>
<body bgcolor="#FFFFFF">
<form name="image" method="post" action="libcatlist.asp?action=update&updimage=105971&high=&low=">
  <p><font face="Verdana, Arial, Helvetica, sans-serif" size="2"><img name="logo" src="../images/logo_admin.gif" width="111" height="45" border="0" alt="bluegreen marine and travel picture library"><br>
    <br>
    <b class="subjecttitle">Library Management - Update Image Details</b></font></p>
  <p><img src="../library/main/ <font face="Arial" size=2>error '80020009'</font>
<p>
<font face="Arial" size=2>Exception occurred.
</font>
<p>
<font face="Arial" size=2>/admin/libupdate.asp</font><font face="Arial" size=2>, line 21</font> 

and the code in the script


try
							set thesource to do shell script "curl http://www.b....s.com/admin/libupdate.asp?updimage=" & imageNumber
						on error theError
							display dialog theError
						end try
set theIf to "Exception"

^-- curl


if thesource contains theIf then
									repeat with i from 1 to elementCount
										--makes the image number to item 1 of the list
										if i is equal to 6 or i is equal to 12 then
										else
											--this puts all the information from the textfields in the form to the list
											set item i of elementValueList to "XXXXXXXXXXXXX"
										end if
										
									end repeat
									
								else if thesource does not contain theIf then
									repeat with i from 1 to elementCount
										--makes the image number to item 1 of the list
										if i is equal to 6 or i is equal to 12 then
										else
											--this puts all the information from the textfields in the form to the list
											set item i of elementValueList to do script "window.document.forms[0].elements[" & (i - 1) & "].value"
										end if
										
									end repeat
								end if

Basically what should happen is if the page has this unique word then excel should fillt the fields with XXXX if its not then it should get the information.

But it doesnt wrok

What “doesn’t work”? If the trouble is looking in the HTML returned from curl, try passing the result from curl through grep.

it should have looked through the source and found the isIf variable.

Bvut it doesn’t.

how would i use grep to help?

Use the info from your curl stdin by sending it to the AppleScript Text Item Delimiter.

try 
set thesource to do shell script "curl http://www.b....s.com/admin/libupdate.asp?updimage=" & imageNumber 
                  on error theError 
                     display dialog theError 
                  end try 
set {oldDelims, AppleScript's text item delimiters} to {AppleScript's text item delimiters, "Exception"}
set theIf to text items of HTMLText
set AppleScript's text item delimiters to oldDelims

This creates a list, then go through the list and find what you are looking for.

repeat with i in theelf
	set thisText to i as text
	set notThisString to "<html>" as text
	if the text of thisText begins with notThisString then
		set thisIsIt to false
	else
		set thisIsIt to true
		exit repeat
	end if
end repeat

hope this helps

i dont understand what the above post does, can someone explain it for me please?

thanks.

Also have simply copied and pasted but the if statement, which should see wether the source code contains a word “Exception” then something shopuld happen.

My post is very incomplete; there is no true script but snippets of examples.
Here is a complete script that uses curl to use google as search engine for walmart.com. You input an artist name and a album name and the script uses that string, after parsing the text for acceptable web & ascii characters, to find the UPC of the artists album. I use TID’s to make a list of the curl stdout information and then repeating through the list get just the UPC. I could have instead made a list of all the artists albums UPCs by repeating through the list in TID’s and wrote that list to a file or any application.
Again, you will need to write your own script with your purposes in mind. Or maybe post more of your script here to get more help.

Get Album UPC of Artist

property trick_Google : "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)"
property search_URL : "http://www.google.com/search?&ie=ISO-8859-1&q="
property search_URL2 : "%22UPC+Code%3A%22+site%3Awww.walmart.com&btnG=Google+Search"
property theUPC : ""
property WM_UPC : ""

set the target_string to "Enter an Artist Name to list all the albums or enter an Artist & Album Name to get just that album."
--display dialog target_string default answer "Enter an Artist Name" buttons {"OK"} default button 1
display dialog target_string default answer "Enter an Artist & Album Name" buttons {"Cancel", "Ok"} default button 2
copy the result as list to {text_returned, button_pressed}
set this_searchstring to text_returned as string
set the encode_searchstring to my encode_text(this_searchstring, true, true)
set the final_url to (search_URL & encode_searchstring & search_URL2)
access_website(final_url)
display dialog theUPC
on access_website(this_URL)
	ignoring application responses
		set Curl_String to "curl -A" & " " & (quoted form of trick_Google) & " " & (quoted form of this_URL)
		set HTMLText to (do shell script Curl_String)
		set {oldDelims, AppleScript's text item delimiters} to {AppleScript's text item delimiters, "<b>Code</b>: "}
		set theParts to text items of HTMLText
		-- set the TIDs back for safety: 
		set AppleScript's text item delimiters to oldDelims
		
		repeat with i in theParts
			set thisText to i as text
			display dialog thisText
			set notThisString to "<html>" as text
			if the text of thisText begins with notThisString then
				set thisIsIt to false
			else
				set thisIsIt to true
				exit repeat
			end if
		end repeat
		if thisIsIt then
			set textLength to length of thisText
			set searchStringLength to 13
			set UPCTemp to (text 1 thru searchStringLength of thisText)
			--display dialog UPCTemp as text
			checkUPC(UPCTemp)
		end if
	end ignoring
end access_website

on encode_text(this_text, encode_URL_A, encode_URL_B)
	set the standard_characters to ¬
		"abcdefghijklmnopqrstuvwxyz0123456789"
	set the URL_A_chars to "$+!'/?;&@=#%><{}[]"~`^\|*"
	set the URL_B_chars to ".-_:"
	set the acceptable_characters to the standard_characters
	if encode_URL_A is false then ¬
		set the acceptable_characters to ¬
			the acceptable_characters & the URL_A_chars
	if encode_URL_B is false then ¬
		set the acceptable_characters to ¬
			the acceptable_characters & the URL_B_chars
	set the encoded_text to ""
	repeat with this_char in this_text
		if this_char is in the acceptable_characters then
			set the encoded_text to ¬
				(the encoded_text & this_char)
		else
			set the encoded_text to ¬
				(the encoded_text & encode_char(this_char)) as string
		end if
	end repeat
	return the encoded_text
end encode_text

on encode_char(this_char)
	set the ASCII_num to (the ASCII number this_char)
	set the hex_list to ¬
		{"0", "1", "2", "3", "4", "5", "6", "7", "8", ¬
			"9", "A", "B", "C", "D", "E", "F"}
	set x to item ((ASCII_num div 16) + 1) of the hex_list
	set y to item ((ASCII_num mod 16) + 1) of the hex_list
	return ("%" & x & y) as string
end encode_char

on checkUPC(UPCTemp)
	set itsOK to false
	repeat until itsOK
		set theUPC to UPCTemp
		if length of theUPC is 13 then
			repeat with i from 1 to 13
				if {"1", "2", "3", "4", "5", "6", "7", "8", "9", "0"} does not contain ¬
					character i of theUPC then
					exit repeat
				end if
			end repeat
			if i = 13 and {"1", "2", "3", "4", "5", "6", "7", "8", "9", "0"} contains ¬
				character i of theUPC then
				set itsOK to true
				if itsOK = true then
					set UPCTemp to theUPC
					exit repeat
				else
					set msgText to "Invalid UPC!" & return & return & msgText
				end if
			end if
		end if
		set msgText to "Invalid UPC!" & return & return & msgText
	end repeat
end checkUPC