Solved

Replacing content from a cfhttp page grab

Posted on 2003-11-04
6
187 Views
Last Modified: 2013-12-24
I'm trying to search and replace content from a cfhttp page grab. So far it's working fine except that there are dynamicly generated links that I need to append code to the end of. The start of the URL to be edited remains constant on all links however the end of the link changes dynamicly. For example the URL would look something like:
<A HREF=http://www.mywebsitecontent.com/dynamic/stories/E/ELECTION_RDP>  

The URL will remain static except for the last part E/ELECTION_RDP>

What I need to do is append some code on to the end of the URL so that it would look something like:
<A HREF=http://www.mywebsitecontent.com/dynamic/stories/E/ELECTION_RDP?SITE=MYSITE&SECTION=HOME>

The code that I am appending to the end of the URL will remain constant, I just need a way for the searh and replace function to find the end of the URL and append my code on the end.

Here is an example of what I have been doing to format the output from the cfhttp:

<cfhttp method="get" url="www.mywebsitecontent.com/TOPHEADLINE_THREE_ONLY-rich.html" resolveurl="yes">
</cfhttp>

<cfset newText = reReplaceNoCase(cfhttp.filecontent, "<SPAN CLASS='byttl'><br>[^<]+</span>", "", "ALL")>
<cfset newText2 = reReplaceNoCase(newText, "<SPAN[^>]+>", "", "ALL")>
<cfset newText3 = reReplaceNoCase(newText2, "<IMAGE[^>]+ >", "", "ALL")>
<cfset newText4 = reReplaceNoCase(newText3, "<IMG[^>]+>", "", "ALL")>
<cfset newText5 = reReplaceNoCase(newText4, "<TABLE[^>]+>", "", "ALL")>
<cfset newText6 = reReplaceNoCase(newText5, "<TR[^>]+>", "", "ALL")>
<cfset newText7 = reReplaceNoCase(newText6, "<TD[^>]+>", "", "ALL")>
<cfset newText8 = reReplaceNoCase(newText7, "<FONT[^>]+>", "", "ALL")>
<cfset newText9 = reReplaceNoCase(newText8, "<!--[^>]+>", "", "ALL")>

<cfset output = #ReplaceList(newText9, "<TR>,</TR>,<TD>,</TD>,</TABLE>,&nbsp;,</SPAN>" , ",,,,,,")#>

<cfoutput>#output#</cfoutput>

I think it would be possible to replace the part of the URL I need to change using a reReplaceNoCase if I there was some kind of wild card for the code that is dynamic.
0
Comment
Question by:McHack
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 15

Expert Comment

by:danrosenthal
ID: 9683439
This should do it...

<CFSET my_string = "<A HREF=http://www.mywebsitecontent.com/dynamic/stories/E/ELECTION_RDP>">

<CFSET my_string = REREPLACENOCASE(my_string,
"(<A[^>]+)(HREF=""?)+([^ ""\>]*)(.*)","\1\2\3&YourAdditionHere=1\4","ALL")>

<CFOUTPUT>
#htmlcodeformat(my_string)#
</CFOUTPUT>
0
 
LVL 4

Expert Comment

by:procept
ID: 9685098
Hi,

I would make a very little change to danrosenthal's code, to also include tags that quote the attributes with single quotes:
<CFSET my_string = REREPLACENOCASE(my_string,
"(<A[^>]+)(HREF=[""']?)+([^ ""'\>]*)(.*)","\1\2\3&YourAdditionHere=1\4","ALL")>

Chris




0
 

Author Comment

by:McHack
ID: 9688403
Well I just can't get it to work. I've been working with it for quit a while and one time I did get just the first URL to work but I'm not sure what I did I just don't have a very good understanding of regular expressions (does any one know of a good online reference for regular expressions?) Anyway it seems to me if there was a way to search for the ending ">" in the URLs and replace them with "SITE=MYSITE&SECTION=HOME>" all should be good. Any ideas?

Thanks
0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 

Author Comment

by:McHack
ID: 9688469
Correction, that last line in my message should have read:
"?SITE=MYSITE&SECTION=HOME>"
0
 
LVL 4

Accepted Solution

by:
procept earned 250 total points
ID: 9693031
Hi,

just replacing the ">" can be done, but, what if you encounter URLs with more attributes than just href, or if the href attribute is quoted???

I just tested the reg ex, and, it works perfectly. Just replace "myString" with your variable. Maybe you can show us some code...

If you are 100% sure that there never will be any other attributes and that there never will be quotes around the href, the following might do.
<CFSET my_string = REREPLACENOCASE(my_string, "(<A HREF=[^<]+)>", "\1&YourAdditionHere=1>","ALL")>

HTH,

Chris
0
 

Author Comment

by:McHack
ID: 9720318
Hey Crhis , I've been running the last idea you had (replacing ">") for several days and it's been working great!  Thanks a lot!
0

Featured Post

Don't Miss ATEN at InfoComm 2017!

Visit booth #2167 to see the  new ATEN VM3200 32 x 32 Modular Matrix Switch. Other highlights include the VE8950 4K HDMI Over IP Extender, VS1912 12-Port DP Video Wall Media Player  and VK2100 ATEN Control System. Register now with Free Pass Code ATEN288!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A web service (http://en.wikipedia.org/wiki/Web_service) is a software related technology that facilitates machine-to-machine interaction over a network. This article helps beginners in creating and consuming a web service using the ColdFusion Ma…
Article by: kevp75
Hey folks, 'bout time for me to come around with a little tip. Thanks to IIS 7.5 Extensions and Microsoft (well... really Windows 8, and IIS 8 I guess...), we can now prime our Application Pools, when IIS starts. Now, though it would be nice t…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question