Skip to main content
Known Participant
March 8, 2007
Question

Replace content in CFHTTP content

  • March 8, 2007
  • 4 replies
  • 854 views
We are using CFHTTP to grab some content from a sister site of ours. When displaying the cfhttp.FileContent we want to remove certain elements from the page. The problem is the elements to remove are often large chunks of code as opposed to just a word here and there. I tried doing a cfsavecontent variable and replace the cfhttp.FileContent stream with the cfsavecontent variable but it doesn't want to work. Is there an easier way to do this? Like specify a starting point of the chunck of code to remove and an end point and removing everything from the start to the end point from the cfhttp stream?

THANKS
    This topic has been closed for replies.

    4 replies

    Inspiring
    March 9, 2007
    It looks like the <hr> tags break your content up nicely. You could use FindNoCase() to locate them and then use those positions to break up your content. Or perhaps this could be done easily with regular expressions, but I'm not really a RegExp guy.
    BKBK
    Community Expert
    Community Expert
    March 10, 2007
    thanks guys, ok so here is the URL I am usng in the CFHTTP:

    http://www.truckpaper.com/listings/forsale/list.asp?pcid=391030&etid=1&bcatid=27&dlr=1

    I would liek it to ONLY return the search results table. So I need to remove the header information at the top and the search form and everything else at the bottom. So the first thing you will see is the beige table row with the column headers and the last thing you will see is the links to go to the next two pages.


    The blocks you wish to replace contain arbitrary spaces, perhaps even dynamic elements. I don't think it is advisable to use the cfsavecontent tag. In string search and replacement, every character counts. It is surgery by laser.

    What you need here is an axe. For example, if you chop off the contents of the first form and the last two forms, you will get a result close to what you seek.



    BKBK
    Community Expert
    Community Expert
    March 9, 2007
    ... the elements to remove are often large chunks of code ...
    ... replace the [the cfsavecontent variable in ] cfhttp.FileContent stream ...
    ... but it doesn't want to work...

    I think the cfsavecontent approach would work. However, every character counts in a search or replace. There should therefore be nothing between the cfsavecontent tags and the chunk of code. You should have

    <cfsavecontent variable="blockToDelete">[chunk of code]</cfsavecontent>

    and not, for example,

    <cfsavecontent variable="blockToDelete">
    [chunk of code]
    </cfsavecontent>


    Known Participant
    March 9, 2007
    thanks guys, ok so here is the URL I am usng in the CFHTTP:

    http://www.truckpaper.com/listings/forsale/list.asp?pcid=391030&etid=1&bcatid=27&dlr=1

    I would liek it to ONLY return the search results table. So I need to remove the header information at the top and the search form and everything else at the bottom. So the first thing you will see is the beige table row with the column headers and the last thing you will see is the links to go to the next two pages.

    Thanks
    Participating Frequently
    March 9, 2007
    Did you try using,

    ReplaceNoCase(string, substring1, substring2 [, scope ])
    OR
    RemoveChars(string, start, count)

    Thanks

    Sankalan
    (www.mindfiresolutions.com)
    Inspiring
    March 8, 2007
    Like specify a starting point of the chunck of code to remove and an end
    point and removing everything from the start to the end point from the
    cfhttp stream?


    Yes, because it is not a stream. It is a large string variable and all
    string functions work on it; mid(), left(), right(), replace(), find(),
    rereplace(), refind(), ect().
    Known Participant
    March 8, 2007
    Right, I know it is just a long string variable, but I just cant figure out what string functions to perform and in what order etc to do what I want.