[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

How to fetch images from web page with relative path

Yi Zheng

9/5/2008 7:39:00 AM

Hi, all

here is the code, it works when the image has a full path, but I met
some pages which only gives relative path for images. How to handle this
condition?

Thanks a lot!

def self.get_magick_img_from_url(url)
begin
blob =''
img_file = nil
Timeout::timeout(5) {
#open web page
img_file = open(url)
}
if img_file
#read page content and store into blob
img_file.readlines().each() do |line|
blob << line
end
img_file.close()
#fetch images here
return Magick::Image.from_blob(blob)
end
rescue Timeout::Error
puts 'Timeout in get_magick_img_from_url for url - ' + url
rescue
puts 'Error in get_magick_img_from_url - ' + $!
end
return nil
end
--
Posted via http://www.ruby-....

5 Answers

Yi Zheng

9/5/2008 7:42:00 AM

0

BTW, I use rmagick.
--
Posted via http://www.ruby-....

Lex Williams

9/5/2008 8:47:00 AM

0

Yi Zheng wrote:
> BTW, I use rmagick.

What do you use to get the links ?
--
Posted via http://www.ruby-....

Lex Williams

9/5/2008 10:16:00 AM

0

Yi Zheng wrote:
> Hi Lex,
>
> I use open-uri, any tip about this?

Would you consider switching to mechanize ? It can handle relative links
as well as absolute ones . With mechanize you could get all the pictures
in a very easy way .
--
Posted via http://www.ruby-....

Yi Zheng

9/7/2008 12:12:00 PM

0

Lex Williams wrote:
> Yi Zheng wrote:
>> Hi Lex,
>>
>> I use open-uri, any tip about this?
>
> Would you consider switching to mechanize ? It can handle relative links
> as well as absolute ones . With mechanize you could get all the pictures
> in a very easy way .

Thanks Lex, I will try.
--
Posted via http://www.ruby-....

Raveendran Jazzez

4/20/2009 9:50:00 AM

0

Hi All,

Get all images from given URL

Desktop Application from jazzez

Kindly go through below link and download the EXE file.

http://www.box.net/shared/...

Install in Windows machine and enjoy with impressed images

Regards,
P.Raveendran
http://raveendran.wor...
--
Posted via http://www.ruby-....