Solved

fetching all images from a URL

Posted on 2013-06-28
7
62 Views
Last Modified: 2015-02-27
i need to get images from a webpage source. i can use cfhttp to load page contents

need to loop through the content to get all image url's(src)

can i use rematch() or refind() etc... and if yes how??

if im not clear i can try to clarify..

with that, once i fetch images, i just want to specify to fetch images which has image size of 800*600 only

Any idea
0
Comment
  • 4
  • 3
7 Comments
 
LVL 15

Expert Comment

by:Tomarse111
ID: 39289980
This should do the trick for getting the images and checking their width and height:

<cfhttp url="YOUR_URL_HERE" method="get">
<cfset images = reMatchNoCase("<img ([^>]*[^/]?)>", cfhttp.FileContent)>


<cfloop array="#images#" index="img">
	<cfset src="YOUR_URL_HERE#REReplace(img, "^.*<img[^>]+src=(['""])([^'""]+)\1[^>]*>.*$", "\2")#">
	<cfset imgInfo=ImageNew(src)>
	
	<cfif imgInfo.width EQ 800 AND imgInfo.height EQ 600>
		
		<!--- DOWNLOAD IMAGE --->
		
	</cfif>
	
</cfloop>

Open in new window

0
 
LVL 15

Author Comment

by:Gurpreet Singh Randhawa
ID: 39292229
I am getting url like this

http://www.santabanta.com/photos/neha-dhupia/443114.htm?high=1http://media.santabanta.com/medium1/Global Celebrities(F)/Sunny Leone/sunny-leone-75a.jpg
0
 
LVL 15

Expert Comment

by:Tomarse111
ID: 39292434
Could you please show the code you are using, with the the CFHTTP url as well.

Tom
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 15

Author Comment

by:Gurpreet Singh Randhawa
ID: 39295603
this is the code i used:

<cfhttp url="http://www.santabanta.com/photos/neha-dhupia/443114.htm?high=1" method="get">
<cfset images = reMatchNoCase("<img ([^>]*[^/]?)>", cfhttp.FileContent)>


<cfloop array="#images#" index="img">
	<cfset src="YOUR_URL_HERE#REReplace(img, "^.*<img[^>]+src=(['""])([^'""]+)\1[^>]*>.*$", "\2")#">
	<cfset imgInfo=ImageNew(src)>
	
	<cfif imgInfo.width EQ 800 AND imgInfo.height EQ 600>
		
		Using cfcontent here
		
	</cfif>
	
</cfloop>

Open in new window

0
 
LVL 15

Accepted Solution

by:
Tomarse111 earned 500 total points
ID: 39295910
Ah that's ok, the URLs for the img srcs are absolute (that's bad by the way) so you need line 6 to be changed:

<cfhttp url="http://www.santabanta.com/photos/neha-dhupia/443114.htm?high=1" method="get">
<cfset images = reMatchNoCase("<img ([^>]*[^/]?)>", cfhttp.FileContent)>


<cfloop array="#images#" index="img">
	<cfset src="#REReplace(img, "^.*<img[^>]+src=(['""])([^'""]+)\1[^>]*>.*$", "\2")#">
	<cfset imgInfo=ImageNew(src)>
		
	<cfif imgInfo.width EQ 800 AND imgInfo.height EQ 600>
		
		Using cfcontent here
		
	</cfif>
	
</cfloop>

Open in new window

0
 
LVL 15

Author Comment

by:Gurpreet Singh Randhawa
ID: 39820497
i tried the code but it does not fetch all images

this link

http://www.santabanta.com/wallpapers/neha-dhupia/

shows the images of the celebrity in thumbnail positions, with paging at the bottom, need to fetch the 800 *600 of all the images of the that celebrity, i know i am asking too much
0
 
LVL 15

Author Closing Comment

by:Gurpreet Singh Randhawa
ID: 40634918
Thanks, Changing few things made it work
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Today, I was working on some optimization and spam-stopping techniques when I encountered Ben Nadel's post to reduce spam feature using Math (http://www.bennadel.com/blog/197-How-I-Stop-Spammers-On-My-ColdFusion-Blog.htm). While this method is not o…
I spent nearly three days trying to figure out how incorporate OAuth in Coldfusion for the Eventful API. Hopefully, this article will allow Coldfusion Programmers to buzz through the API when they need to. Basically, what this script does is authori…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

920 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now