Skip to main content
Participant
May 17, 2011
Answered

copy & paste web page info

  • May 17, 2011
  • 2 replies
  • 1058 views

i somewhat new to coldfusion and i can't figure out how to do something..

lets say there is a web page with these texts

hi abc bye

hi 123 bye

hi a1b2 c3 bye

i want to create a page that will go to a specific web page and search throught that web page for the word hi and then grab the following text up to the word bye... then it'll place those text in a file... so for example it'll copy only the text

abc

123

a1b2 c3

...and paste them in a file

is this possible??

can someone please point me in the right direction, i been at this for almost two days!

thanks in advance.

    This topic has been closed for replies.
    Correct answer ilssac

    cfquery_select_name wrote:


    i want to create a page that will go to a specific web page

    So you want to make an HTTP request for a web page, that would be the purpose of the <CFHTTP....> Tag.

    cfquery_select_name wrote:

    search throught that web page

    Then you want to find text in the content returned from the request.  the find() and refind() functions (most likely the later) would be helpful here.

    cfquery_select_name wrote:

    ...and paste them in a file

    Finaly you would like to write output to a file.  The <cffile action="write"...> would be the first choice for this task.

    That just leaves the actual searching.  Like I said I would probably try a REFIND that uses regular expression syntax to find the desired text.  Something like this untested example off the top of my head should get you started.

    <cfset match = refind(searchString,"hi(.*?)bye",1,true)>

    <cfdump var="#match#">

    Then finally a loop over this code to find each instance of the desired string.

    cfquery_select_name wrote:

    is this possible??

    Quite possible, it should just take some trail and error and looking at the appropiate documentation.

    2 replies

    May 18, 2011

    Here is another version using findnocase:

    <cfset string = "hi abc bye hi 123 bye hi a1b2 c3 bye" />
    <cfset StartText = 'hi' />
    <cfset Start = FindNoCase(StartText, string, 1) />
    <cfset EndText='bye' />
    <cfset Length=Len(StartText) />
    <cfset End = FindNoCase(EndText, string, Start) />
    <cfset parse = Mid(string, Start+Length, End-Start-Length) />
    <cfoutput>#parse#</cfoutput>

    If you have to loop through this, you'd have to keep incrementing the start position...

    <cfset Start = FindNoCase(StartText, string, 1) />  the 1 would be replaced with the next start position.

    <cfwild />

    ilssac
    ilssacCorrect answer
    Inspiring
    May 17, 2011

    cfquery_select_name wrote:


    i want to create a page that will go to a specific web page

    So you want to make an HTTP request for a web page, that would be the purpose of the <CFHTTP....> Tag.

    cfquery_select_name wrote:

    search throught that web page

    Then you want to find text in the content returned from the request.  the find() and refind() functions (most likely the later) would be helpful here.

    cfquery_select_name wrote:

    ...and paste them in a file

    Finaly you would like to write output to a file.  The <cffile action="write"...> would be the first choice for this task.

    That just leaves the actual searching.  Like I said I would probably try a REFIND that uses regular expression syntax to find the desired text.  Something like this untested example off the top of my head should get you started.

    <cfset match = refind(searchString,"hi(.*?)bye",1,true)>

    <cfdump var="#match#">

    Then finally a loop over this code to find each instance of the desired string.

    cfquery_select_name wrote:

    is this possible??

    Quite possible, it should just take some trail and error and looking at the appropiate documentation.

    Participant
    May 18, 2011

    ok, i didn't want to come back on here and continue to bother you guys but i'm still stuck...

    this s my code..


    <cfhttp url = "http://www.sitename.com/index.cfm">
        <cfset match = refind("hi(.*?)bye",1,true)>
    </cfhttp>

    <cfdump var="#match#">

    <cffile
        action = "write"
        file = "C:\Desktop\here.txt"
        output = "#match#">


    ...you had this <cfset match = refind(searchString,"hi(.*?)bye",1,true)> but i got an error saying "Complex object types cannot be converted to simple values." i removed it to see what will happen and now a zero shows up on the web page and in the txt document there is also a 0, the text inbetween "hi" and "bye" doesn't "write" to the document file.

    Community Expert
    May 18, 2011

    First, you should probably refer to the ColdFusion documentation when someone tells you to use a specific tag or function, so that you understand the syntax of that tag or function.

    Second, the CFHTTP tag doesn't allow you to just embed child tags within it. The only acceptable child tag of CFHTTP is CFHTTPPARAM.

    Third, you'll want to use the returned value from the CFHTTP request. That value is called CFHTTP.fileContent. You have to refer to that explicitly:

    <cfhttp url="..."/>

    <cfdump var="#CFHTTP.fileContent#">

    Fourth, you'll want to use that value in REFind. You're not specifying any string to search against.

    Dave Watts, CTO, Fig Leaf Software

    http://www.figleaf.com/

    http://training.figleaf.com/

    Dave Watts, Eidolon LLC