View Single Post
  #23 (permalink)  
Old 02-18-2008, 10:11 PM
prasannavigneshr prasannavigneshr is offline
D-Web Incredible
 
Join Date: Feb 2007
Posts: 1,321
prasannavigneshr is on a distinguished road
Send a message via MSN to prasannavigneshr
Thumbs up ColdFusion Tips & Tricks - Grabbing informaion from another website

Grabbing informaion from another website


If you want to grab a bit of information from another website, you can use the CFHTTP tag to pull in the HTML of the site in question and store it in a variable.

I did basically the same thing in creating a Comic's page that lists all of my favorite comics. It has to scan a few of the comic websites each day since they use a seemingly random number as part of the GIF file names that changes from day to day. Attached is an excerpt of my code that I use to search the html for the GIF file name.

Basically, you need to know of a string of text that will never change (you hope) in it's position to whatever information you want. Search for the location of this string of text and if you find it, search after it for the last of the text you want.

Feel free to steal it. : P Note that it's been a couple months since I used this program so maybe it'll still find the Dilbert strip, maybe it won't.



Example HTML/CFML code:
Code:
<!--- Main program --->

<CFSET title="Dilbert">
<CFSET base="http://www.dilbert.com">
<CFSET url="http://www.dilbert.com/comics/dilbert/">
<CFSET search="/comics/dilbert/archive/images/dilbert">
<CFINCLUDE TEMPLATE="ComicSearch.cfm">
<CFINCLUDE TEMPLATE="HTML.cfm">

<!--- ComicSearch.cfm --->
<CFSET ck=0>

<CFHTTP URL="#url#"
        METHOD="GET">
</CFHTTP>
<CFSET dat=CFHTTP.FileContent>

<CFSET loc1=Find(search,dat)>
<CFIF loc1 EQUAL 0>
  <CFSET ck=1>
<CFELSE>
  <CFSET loc2=Find(Chr(34),dat,loc1)>
  <CFSET strip="#base##Mid(dat,loc1,loc2 - loc1)#">
</CFIF>

<!--- HTML.cfm --->
<CFOUTPUT>
<table border="0" width="90%"><tr><td BGCOLOR="##FFFF00">
<font face="Arial" size="5">&nbsp;&nbsp;#title#</font>
</td></tr></table>
</CFOUTPUT>

<CFIF ck EQUAL 0>
  <CFOUTPUT>
  <a href="#url#"><img src="#strip#" border="0"></a><br><br>
  </CFOUTPUT>
<CFELSE>
  <CFOUTPUT>Unable to determine the image filename<br><br></CFOUTPUT>
  <CFSET ck=0>
</CFIF>
__________________
Prasanna Vignesh
MCPD | Web Developer
Reply With Quote