Building Astute Web Specialists with CFML Michael Dinowitz November, 2000.


70 views
Uploaded on:
Description
A page from ebay with the consequences of a pursuit. 2. Characterize how it will ... <cfhttp url=
Transcripts
Slide 1

Building Intelligent Web Agents with CFML Michael Dinowitz November, 2000

Slide 2

Intelligent Agents in ColdFusion What are Agents? Code that does programmed work for you Involves recovering data Processing or putting away that data Usually a solitary page or has no interface What are Intelligent Agents (IA)? Term client for a particular class of specialists Retrieves remote data Processes the recovered data Decision making code worked in Usually includes Parsing operations Interfaces with remote procedures

Slide 3

Intelligent Agents in ColdFusion What aren\'t Intelligent Agents? Push of any kind (CFMAIL) Calls to organized areas DBs LDAP Browsers Gray Areas - Structured information Syndicated information (Spectra) HTTP inquiry returns Comma delimited data Most nearby data calls

Slide 4

Intelligent Agents in ColdFusion Broad cases CF_StockGrabber - snatches and prepared stock data CF_UPS - interface to UPS shipping information CF_MetaSearch - seeks various web indexes and groups comes about CF_GetTags

Slide 5

Intelligent Agents in ColdFusion Technologies utilized for recovery CFHTTP - recover sites CFFTP - recovers ftp data CFX_Socket - attachment calls for data CFX_NNTP - recovers usenet news Technologies utilized for parsing Find()/FindNoCase () Replace()/ReplaceNoCase () Mid() REFind()/REFindNoCase () REReplace()/REReplaceNoCase()

Slide 6

IA method I - CF_EbayItem IA procedure I - CF_EbayItem 1. Characterize what you need A page from ebay with the aftereffects of an inquiry 2. Characterize how it will be shown Whole page returned in a variable. No parsing 3. Characterize the means to get it CFHTTP to recover a page Place data in record or on program

Slide 7

CFHTTP Basics <CFHTTP Url - Url to recover. Does not require http://prefix Method - Get or Post. ResolveUrl - Turns every relative connection into "full" ones. Required for design and connections from the page. Takes note of: The URL does not should be prefixed by http://, however it\'s great practice to do as such. Get is standard and utilizations the tag \'as seems to be\'. Post requires a CFHTTPPARAM and in addition an end CFHTTP tag. ResolveUrl ought to just be utilized when you hope to take after connections from the called page or need to see the media content.

Slide 8

IA system I - CF_EbayItem <!- - CF_EbayItem - Module to get all things from ebay and return it - > <!- - Required characteristics - > <CFPARAM name="attributes.searchitem"> <CFPARAM name="attributes.ReturnVar" default="ReturnVar"> <cfhttp url="http://look desc.ebay.com/seek/search.dll?MfcISAPICommand=GetResult&ebaytag1=ebayreg&ht=1&query=#attributes.searchitem#&ebaytag1code=0&srchdesc=y&SortProperty=MetaNewSort" method="GET" resolveurl="true"> <CFSET "Caller.#Attributes.ReturnVar#"=CFHttp.FileContent> IA procedure I - CF_Ebay (Code)

Slide 9

IA strategy II - CF_EbayItem 1. Characterize what you need All things from an ebay look 2. Characterize how it will be shown in an arrival exhibit 3. Characterize the string to hunt down in the page <a href="http://cgi.ebay.com/aw-cgi/eBayISAPI.dll?ViewItem&item=449570667">HEBREW AMULETS: By T Schrire</a> 4. Characterize the means to get it CFHTTP to recover a page CFLOOP over the page for components FindNoCase() to get begin of particular component FindNoCase() to get end of particular component Mid() to get entire component Place data in cluster for return

Slide 10

Find()/FindNoCase() Basics FindNoCase ( substring , string [, begin ]) SubString - The definite string your searching for String - The string that you\'re looking Start - Optional begin position. Notes: FindNoCase is marginally slower, yet better when you don\'t know precisely what you\'re searching for. Continuously a smart thought to set a begin. Speeds up the pursuit. Keep in mind that the arrival quality is the START position of the SubString. Add the SubString length to get the end position.

Slide 11

Mid() Basics Mid ( string , begin , number ) String - The string that contains the SubString you need. Begin - The begin position of the SubString you need. Tally - The measure of characters in the SubString that you need. Notes: When utilized with FindNoCase, it is common to have a begin variable and an end variable. The tally would then be noted as End-Start

Slide 12

IA strategy II - CF_EbayItem <!- - CF_EbayItem - Module to get all things from ebay and return it - > <!- - Required characteristics - > <CFPARAM name="Attributes.SearchItem"> <CFPARAM name="Attributes.ReturnArray" default="ReturnArray"> <cfhttp url="http://look desc.ebay.com/seek/search.dll?MfcISAPICommand=GetResult&ebaytag1=ebayreg&ht=1&query=#Attributes.SearchItem#&ebaytag1code=0&srchdesc=y&SortProperty=MetaNewSort" method="GET" resolveurl="true"> <CFSET End=1> <!- - Set neighborhood exhibit for capacity. We set all qualities to a nearby exhibit as opposed to the calling format to decrease the quantity of "calls" amongst layouts and enhance execution. - > <CFSET LocalArray=ArrayNew(1)> <!- - CF_EbayItem - Module to get all things from ebay and return it - > <!- - Required qualities - > <CFPARAM name="attributes.searchitem"> <CFPARAM name="attributes.ReturnVar" default="ReturnVar"> <cfhttp url="http://look desc.ebay.com/seek/search.dll?MfcISAPICommand=GetResult&ebaytag1=ebayreg&ht=1&query=#attributes.searchitem#&ebaytag1code=0&srchdesc=y&SortProperty=MetaNewSort" method="GET" resolveurl="true"> <CFSET "Caller.#Attributes.ReturnVar#"=CFHttp.FileContent>

Slide 13

IA strategy II - CF_EbayItem <CFLOOP condition="1"> <CFSET Start = FindNoCase(\'<a href="http://cgi.ebay.com/aw-cgi/eBayISAPI.dll?ViewItem&item=\', cfhttp.filecontent, end)> <CFIF Start> <!- - Add the pursuit thing\'s length to its position to get its actual end position. This will help in getting its full esteem in the Mid() capacity. - > <CFSET End=FindNoCase(\'</a>\', cfhttp.filecontent, start)+4> <!- - Add thing to a nearby exhibit - > <CFSET ArrayAppend(LocalArray,Mid(cfhttp.filecontent, begin, end-start))> <cfelse> <cfbreak> </cfif> </cfloop> <!- - Set neighborhood cluster to calling layout - > <CFSET "caller.#Attributes.ReturnArray#"=LocalArray>

Slide 14

IA procedure III - CF_EbayItem 1. Characterize what you need All things from an ebay look 2. Characterize how it will be shown in an arrival cluster 3. Characterize the string to hunt down in the page <a href="http://cgi.ebay.com/aw-cgi/eBayISAPI.dll?ViewItem&item=449570667">HEBREW AMULETS: By T Schrire</a> 4. Characterize the means to get it CFHTTP to recover a page CFLOOP over the page for components REFindNoCase() to get particular component Mid() to get entire component Place data in exhibit for return

Slide 15

REFind()/REFindNoCase() Basics REFindNoCase ( RegEx , String [, begin ] [, returnsub ] ) RegEx - Regular Expression to use as inquiry criteria String - String to look in Start - Position in String to begin seek at ReturnSub - Returns sub expressions as characterized in the RegEx Notes: Start ought to dependably be utilized as it velocities up the pursuit. In the case of utilizing ReturnSub, it is required and can be set to 1. This capacity gives back the numeric position of the hunt down content unless ReturnSub is determined. At that point it gives back a structure

Slide 16

REFind()/REFindNoCase() Basics Structure returned by this string will have two keys (Pos, Len) with every key being an exhibit. The main cluster (Variable.Pos[1], Variable.Len[1]) will dependably contain the position/Length of the ENTIRE match. Each extra exhibit component will contain the position and length of a subelement. Variable Pos [1] [2] Len [1] [2]

Slide 17

RegEx Basics The accompanying is a quick once-over of critical characters in Regular Expressions In many cases, a character is equivalent to itself A \ will get away from any exceptional character A period (.) speaks to any one character .at can mean bat, feline, rodent, or anything that has a solitary character and closures with at. A couple of sections indicates an arrangement of characters (I.e. one of them can be utilized) [01256] implies any of those numbers A dash (- ) inside a set signifies "a scope of" [0-9] implies any single number of 0 through 9 A carat (^) inside a reach signifies "Not the extent" [^aeiou] implies any character but rather a vowel

Slide 18

RegEx Basics Parenthesis is utilized to indicate a compound expression OR a subexpression (this) will give back the position and length of "this" When utilized inside an intensify, a channel (|) implies either/or (this|that) will give back the position and length of the principal event of "this" or "that" A question mark (?) implies that the past character, set or compond could conceivably exist however in the event that it wills, exist 1 time An or more (+) implies that the past character, set or compond must exist 1 or more times An indicator (*) implies that the past character, set or compond may exist 0 or more times

Slide 19

IA system III - CF_EbayItem <!- - CF_EbayItem - Module to get all things from ebay and return it - > <!- - Required traits - > <CFPARAM name="Attributes.SearchItem"> <CFPARAM name="Attributes.ReturnArray" default="ReturnArray"> <cfhttp url="http://look desc.ebay.com/seek/search.dll?MfcISAPICommand=GetResult&ebaytag1=ebayreg&ht=1&query=#Attributes.SearchItem#&ebaytag1code=0&srchdesc=y&SortProperty=MetaNewSort" method="GET" resolveurl="true"> <CFSET end=1> <!- - Set neighborhood cluster for capacity. We set all qualities to a neighborhood cluster as opposed to the c

Recommended
View more...