Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

fetching all images from a URL

Posted on 2013-06-28
7
Medium Priority
?
75 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
[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
  • 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 16

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
Command Line Tips and Tricks

The command line is a powerful tool at the disposal of every Linux user. Although Linux distros come with beautiful user interfaces, it's worthwhile to learn the command line because it allows you to do a number of things that you otherwise cannot do from the GUI.  

 
LVL 16

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 2000 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 16

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 16

Author Closing Comment

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

Featured Post

AWS Certified Solutions Architect - Associate

This course has been developed to provide you with the requisite knowledge to not only pass the AWS CSA certification exam but also gain the hands-on experience required to become a qualified AWS Solutions architect working in a real-world environment.

Question has a verified solution.

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

PROBLEM:  How to open a cfwindow or run a function on double click of a cfgrid row. One of my clients wanted to be able to double click on a row item to get more detailed information about a transaction and to be able to modify the line items i…
PROBLEM: How to add your own buttons to the bottom toolbar with paging info ( result count ). While creating a cfgrid, I ran into an issue where I wanted to embed my own custom buttons where the default ones ( insert / delete / etc… ) are for aes…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

661 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