Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Alter CFHTTP.FileContent (URGENT) 1

Status
Not open for further replies.

rmz8

Programmer
Aug 24, 2000
210
0
0
US
If you use CFHTTP to GET a web site, and you output it using the CFHTTP.FileContent variable, you cannot alter any part of the HTML. Is there anyway to make it so that the contents of the CFHTTP.FileContent variable can be altered before it is displayed? Essentially, I want to generate HTML using the CFHTTP tag and then alter that HTML (to change font colors, sizes, remove some images, etc.) prior to displaying it on the page. Can this be done? If so, how?

Ryan ;-]
 
CFHTTP.FileContent can be processed just like any other variable. I'm not sure if it is read-only since I generally copy it's content to a new variable. I have worked with this a lot and it can be a little tedious to get the results you want. It is important to work with pages that only change content and not layout.

Andrew
amayer@sonic.net
 
The page only changes content, but that content, although organized into a table, is not really delimited and thus it is hard to make the results a new query. Right now I have built a tag that searches for two points within the HTML and crops everything before and after it. This is functional, but I would rather something that makes the data useable and easily modified (in terms of asthetics).

Ryan ;-]
 
You could try writing to a file.

i.e

<cfhttp url=&quot; method=&quot;GET&quot; resolveurl=&quot;false&quot;></cfhttp>
<cffile action=&quot;WRITE&quot; file=&quot;d:\ output=&quot;#CFHTTP.FileContent#&quot;>

Then you can Read the new file.

<cffile action=&quot;READ&quot; file=&quot;d:\ output=&quot;Content&quot;>


Alter what you need and then write to it again.


Then you can output the new page.

This is long winded, but should do the job
 
I just went to the ColdFusion Conference in Washington DC and learned how to do this. The session was on Building Intelligent Agents.

I just wrote a tag yesterday that gets a page from Ebay, but using the FindNoCase function I only show the item and the price.

Here is the code: Comments are surrounded by **** Remove before running, or change to CF comments



<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;>

<html>
<head>
<title>Untitled</title>
</head>

<body>

***This parameter is sent in through a form and is the item you want to search for***
<CFPARAM NAME=&quot;attributes.searchitem&quot;>
<cfhttp url=&quot; method=&quot;get&quot;></cfhttp>
<cfset End=1>
<cfset End2=1>

***Need two arrays, one to hold item link, one to hold price***
<cfset LocalArray = arraynew(1)>
<cfset LocalArray2 = arraynew(1)>

***Set condition to always be true, we will break out of look in an ELSE condition below***
<cfloop condition=&quot;1&quot;>

<!--- Find the searched for item --->
***The links all begin with the following. I found this out by actually going to Ebay and searching and using View Source. Start is the number of the character where the link begins. End2 is where I start from. It is initialized to 1, but it will be the last position of the price of the previous item. See below***
<cfset Start = FindNoCase('<a href=&quot;

<cfif Start>
<!--- add the closing tags length to its position to get the true end position --->
***End is the end of the link***
<cfset End=findnocase('</a>',cfhttp.filecontent,start)+4>

<!--- add item to array --->
<cfset arrayappend(localarray,mid(cfhttp.filecontent,start,end-start))>
</cfif>
<!--- Find the associated price --->
***do another FindNoCase, starting at the end of the one above***
<cfset Start2 = FindNoCase('<b>$',cfhttp.filecontent,end)></a>
<cfif Start>
<!--- add the closing tag's length to its position to get the true end position --->
<cfset End2=findnocase('</b>',cfhttp.filecontent,start2)+4>

<!--- add item to array --->
<cfset arrayappend(localarray2,mid(cfhttp.filecontent,start2,end2-start2))>
<cfelse>
<cfbreak>
</cfif>

</cfloop>


<!--- Set the variable CountVar to 0 --->
<CFSET CountVar=1>
<cfset Length = ArrayLen(localarray)>
There were <cfoutput>#Length#</cfoutput> items returned.
<br>

<!--- Loop until CountVar = Length --->
<table><CFLOOP CONDITION=&quot;CountVar LESS THAN OR EQUAL TO #Length#&quot;>


<tr><td><CFOUTPUT>#LocalArray[CountVar]#</CFOUTPUT></td><td><CFOUTPUT>#LocalArray2[CountVar]#</CFOUTPUT></td></tr>
<CFSET CountVar=CountVar + 1>
</CFLOOP>
</table>



</body>
</html>



Hope that gets you started.

Kathryn
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top