Image phrase from coldfusion web page

I need to get images from a webpage source.

I can use the cfhttp get method and use htmleditformat () to read html from this page, now I need to scroll through the contents to get all url images (src)

Is it possible to use rematch () or refind (), etc .... and if so, how

Please, help!!!!!

If I do not understand, I can try to clarify ..

+3
source share
3 answers

Here's a feature that probably works in many bad cases, but might work if you just need something quick and dirty.

<cffunction name="getSrcAttributes" access="public" output="No">
    <cfargument name="pageContents" required="Yes" type="string" default="" />

    <cfset var continueSearch = true />
    <cfset var cursor = "" />
    <cfset var startPos = 0 />
    <cfset var finalPos = 0 />
    <cfset var images = ArrayNew(1) />

    <cfloop condition="continueSearch eq true">
        <cfset cursor = REFindNoCase("src\=?[\""\']", arguments.pageContents, startPos, true) />

        <cfif cursor.pos[1] neq 0>
            <cfset startPos = (cursor.pos[1] + cursor.len[1]) />
            <cfset finalPos = REFindNoCase("[\""\'\s]", arguments.pageContents, startPos) />
            <cfset imgSrc = Mid(arguments.pageContents, startPos, finalPos - startPos) />

            <cfset ArrayAppend(images, imgSrc) />
        <cfelse>
            <cfset continueSearch = false />
        </cfif>
    </cfloop>

    <cfreturn images>
</cffunction>

Note. At the moment, I can’t confirm that this code is working.

+1
source
+3

Using a browser and jQuery to “query” from the entire img tag from the DOM might be easier ...

+1
source

Source: https://habr.com/ru/post/1745366/


All Articles