macromedia.coldfusion.advanced_techniques
[Top] [All Lists]

Re: Parsing HTML returned from CFHTTP

Subject: Re: Parsing HTML returned from CFHTTP
From: "BKBK"
Date: Sun, 21 Dec 2008 09:37:31 +0000 UTC
Newsgroups: macromedia.coldfusion.advanced_techniques

You can do it in Coldfusion 8 using the reMatch function, as follows:




 <!--- Extract city, state and country --->
 <cfsavecontent variable="cfhttpResult">
 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> <HTML><HEAD><TITLE>Geo 
Results</TITLE> </HEAD><BODY> VERSION=1.0<br> <p> TARGET: 172.20.85.84<br> 
NAME: IANA-BBLK-RESERVED1<br> NUMBER: 172.16.0.0 - 172.31.255.255<br> CITY: 
AMSTERDAM<br> STATE: NORTH HOLLAND (province) <br> COUNTRY: NL<br> LAT: 
52.35<br> LONG: 4.90<br> LAT_LONG_GRAN: City<br> LAST_UPDATED: <br> NIC: 
RIPE<br> LOOKUP_TYPE: Block Allocation<br> RATING: <br> DOMAIN_GUESS: 
ripe.net<br> STATUS: OK<br> </BODY></HTML>
 </cfsavecontent>

 <!--- Either-Or regex match --->
 <cfset 
city_state_country=REMatch("(CITY:|STATE:|COUNTRY:).*?(<br>)",cfhttpResult)>

 <!--- array of matches (assmued in that order) --->
 <!--- <cfdump var="#city_state_country#"> --->

 <cfset city    = REReplaceNoCase(city_state_country[1],"CITY: |<br>","")>
 <cfset state   = REReplaceNoCase(city_state_country[2],"STATE: |<br>","")>
 <cfset country = REReplaceNoCase(city_state_country[3],"COUNTRY: |<br>","")>

 <p><cfoutput>
 city: #city#<br>
 state: #state#<br>
 country: #country#
 </cfoutput></p>


<Prev in Thread] Current Thread [Next in Thread>