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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to capture page title from previous URL? 1

Status
Not open for further replies.

olchiik

Programmer
May 7, 2009
33
US
Hello,

I have this piece of code to capture page title, but it gives me an error... Please Help!

Code:

<cfoutput><input type="hidden" name="prevurl" value="#CGI.HTTP_REFERER#">
<table width="318" border="0" bgcolor="FFFFFF" align="center">
<cffunction name="getPageTitle" returntype="string" output="false">
<cfargument name="pageurl" type="string" required="true">
<cfhttp method="get" redirect="true" url="#arguments.pageurl#" throwonerror="true"></cfhttp>
<cfreturn ReReplaceNoCase(cfhttp.fileContent, ".*<title>([^<>]*)</title>.*", "\1")>
</cffunction>
<cfset refurl="#CGI.HTTP_REFERER#"></cfoutput>
<cfoutput>#getPageTitle("refurl")#</cfoutput>

Error is in this line:
<cfreturn ReReplaceNoCase(cfhttp.fileContent, ".*<title>([^<>]*)</title>.*", "\1")>....

Just in time compilation error

Invalid token found on line 93 at position 27.( open parentheses) ColdFusion was looking at the following text:(Invalid expression element. The usual cause of this error is a misspelling in the expression text.

The last successfully parsed CFML construct was a CFRETURN tag occupying document position
 
I see a couple of things that seem a little odd,

I might be misreading this but it looks like you're passing the string literal "refurl" in as your URL. you set the refurl variable as the HTTP_REFERER, shouldn't this line read:


<cfoutput>#getPageTitle(refurl)#</cfoutput>

Then the errored line, it all looks ok to me but I've always used "one" as the CFDocs suggest, never tried \1. It might work, it looks like something CF would do :)

try this though:
<cfreturn ReReplaceNoCase(cfhttp.fileContent, ".*<title>([^<>]*)</title>.*", "one") >

let us know if any of that helps. Otherwise we might need to see more code, sometimes a missing character can have affects a long way from where the source is.


Travis Hawkins
jobs.bestcodingpractices.com
 
Hello,

thank you very much for your response.
I have tried it and it still gives me the same error:-(

Error Diagnostic Information
Just in time compilation error

Invalid token found on line 93 at position 27. ColdFusion was looking at the following text:

(

Invalid expression element. The usual cause of this error is a misspelling in the expression text.
The last successfully parsed CFML construct was a CFRETURN tag occupying document position

Is there anything else that I can do to make it work?

Thank you!

 
It sounds like the error could actually on another line. This might seem like a pain but try moving this line down one (just a carriage return is all that's needed). See if the error still says line 93. If it says line 94 then move that line back up and add a carriage return after that line. It's very possible that the error is near there, but not really on that line. For various reasons compilers get the wrong line number from time to time.

Notice in the error message it says the last successful tag is CFRETURN... so it's very possible that the error is actually the next line.

Another thing to try would be separating the ReReplaceNoCase function and the CFRETURN tag, first set a variable to the ReReplaceNoCase function result then try to output that var to be sure it's holding the correct value. Then try Returning it with CFRETURN. That will likely help you track down what the issue is as well.



Travis Hawkins
jobs.bestcodingpractices.com
 
Hi tlhawkins,

I have tried to move it around. It always pints to that open parenthesis. Have no idea what it wants from me. I will try to separate the ReReplaceNoCase function and the CFRETURN tag. Maybe it will work...
Thank you!
 
I have tried to separate the ReReplaceNoCase function and the CFRETURN tag:

Now it looks like this

<cfoutput><input type="hidden" name="prevurl" value="#CGI.HTTP_REFERER#">
<table width="318" border="0" bgcolor="FFFFFF" align="center">
<cffunction name="getPageTitle" returntype="string" output="false">
<cfargument name="pageurl" type="string" required="true">
<cfhttp method="get" redirect="true" url="#arguments.pageurl#" throwonerror="true"></cfhttp>
<cfset reftitle = "#ReReplaceNoCase(cfhttp.fileContent, '.*<title>([^<>]*)</title>.*', 'one')#">
<cfreturn reftitle>
</cffunction>
<cfset refurl="#CGI.HTTP_REFERER#">
#getPageTitle(refurl)# </cfoutput>

and gives me different, but error

ColdFusion cannot determine how to process the tag <CFFUNCTION>. The tag name may be misspelled.

If you are using tags whose names begin with CF but are not ColdFusion tags you should contact Allaire Support.


The error occurred while processing an element with a general identifier of (CFFUNCTION), occupying document position (90:2) to (90:68).

:-( Any ideas?
 
ok, I think I know what must be happening...
Or, maybe I'm just crazy.

Check this out:
<cfset reftitle = "#ReReplaceNoCase(cfhttp.fileContent, '.*<title>([^<>]*)</title>.*', 'one')#">

The Hash marks makes it output that content right where it is. Which is inside quotes. Any content in cfhttp.fileContent is being stuffed inside those quotes. What are the chances that all the content in that file will fit nicely inside those quotes?

Try this:
<cfset reftitle = ReReplaceNoCase(cfhttp.fileContent, '.*<title>([^<>]*)</title>.*', 'one')>

hopefully that gets you running

Travis Hawkins
jobs.bestcodingpractices.com
 
Nope..doesn't work. It gives me same error...

Error Diagnostic Information
ColdFusion cannot determine how to process the tag <CFFUNCTION>. The tag name may be misspelled.

If you are using tags whose names begin with CF but are not ColdFusion tags you should contact Allaire Support.


The error occurred while processing an element with a general identifier of (CFFUNCTION), occupying document position (90:2) to (90:68).
 
Hello,

whatever I do, it's doesn't work. Is there any other way to capture page title? Please help! I need to do it by Friday and I am totallly flustrated...

Thank you
 
I wish I could see what it's doing...

Do you know if your cfhttp.fileContent holds the correct content?

Can you do a ReReplaceNoCase against a string that is what your file SHOULD look like?

I would test each of those pieces separately and see which one is actually failing.

Travis Hawkins
jobs.bestcodingpractices.com
 
When I test
#ReReplaceNoCase(cfhttp.fileContent, ".*<title>([^<>]*)</title>.*", "one")#

it gives me error:

Error Diagnostic Information

An error occurred while evaluating the expression:

#ReReplaceNoCase(cfhttp.fileContent, ".*.*", "one")#

Error near line 8, column 12.

Error resolving parameter CFHTTP.FILECONTENT

ColdFusion was unable to determine the value of the parameter. This problem is very likely due to the fact that either:

1. You have misspelled the parameter name, or
2. You have not specified a QUERY attribute for a CFOUTPUT, CFMAIL, or CFTABLE tag.

The error occurred while processing an element with a general identifier of (#ReReplaceNoCase(cfhttp.fileContent, ".*.*", "one")#), occupying document position (8:11) to (8:85).



Whatever I try..it gives me an error...
 
Oh..that's gives me the right title...:)
I will try to put #CGI.HTTP_REFERER# instead of hard url and see if it will give me same result
 
ups..no...that was not the title...that was content
The wording is almost the same, that's why I thought that was title
 
When I try this

<cfhttp method="get" redirect="true" url="#CGI.HTTP_REFERER#" throwonerror="true"></cfhttp>
<cfoutput>#ReReplaceNoCase(cfhttp.fileContent, ".*<title>([^<>]*)</title>.*", "/1")#</cfoutput>

it outputs /1 ...strange
 
That's kind of what it's supposed to do? you're asking it to search cfhttp.fileContent for ".*<title>([^<>]*)</title>.*" and when it finds it replace it with "/1"

I don't think you want to REPLACE< you just want to FIND the content inside title. Try ReFindNoCase:


I think that's what you're after

Travis Hawkins
jobs.bestcodingpractices.com
 
I have tried <cfhttp method="get" redirect="true" url="#CGI.HTTP_REFERER#" throwonerror="true"></cfhttp>
<cfoutput>#ReFindNoCase( ".*<title>([^<>]*)</title>.*", "cfhttp.fileContent")#</cfoutput>

it outputs 0 and if I take out quotes around cfhttp.fileContent it gives me 1
 
ok, so that's saying it FOUND it... 1 means it found it, if you read the page I sent it explains how to GET what was found. notice the returnsubexpressions = "True"

You're really close to having it

Travis Hawkins
jobs.bestcodingpractices.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top