ColdFusion by example

Posted by coldfury
coldfury has not set their biography yet
User is currently offline
on Wednesday, 13 February 2008
in Digital Blogs
This is a little script that scrapes a postal code site to extract the data they have, for my own database. I posted this to show how little ColdFusion code it actually takes to perform this little operation. CF has handy little features such as CFHTTP to handle the sourcing of the HTML to my local server from where I manipulate it to hearts content.

It took 5 minutes to write and does the job nicely...

<cfset alfaList = "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z">

<cfloop index="p" list="#alfaList#">

<cfset stringLen = len(cfhttp.Filecontent)>
<cfset startPos = find("<hr />", cfhttp.Filecontent)>

<cfset newString = mid(cfhttp.Filecontent, startPos, stringLen)>
<cfset findTD = find("</td>", newString)-7>

<cfset chopString = mid(newString, 7, findTD)>

<cfsavecontent variable="mpc">
<cfoutput>#replace(chopString, "<br />", ",", "ALL")#</cfoutput>

<cffile action="append" file="C:\Inetpub\wwwroot\omega\mpc.txt" output="#mpc#">


Tags: Untagged


Please login first in order for you to submit comments