Home   Archive   Permalink



Website image downloader in Rebol?

I'd like to code an image download program in Rebol, but didn't get far.
    
Currently I have a text field, a button and a text box in my program window. Copy & paste a website address in the text field, click the button and it displays the HTML of the website.
    
1) Instead of showing the HTML, I'd like Rebol to go through that source code and display all images listed in there, or at least get the URL of the thumbnail images.
    
2) Some porn websites (what else would I code this program for? ;) ask something like "are you really 18?", if you click "enter", a cookie is set and you see the actual content.
    
Somehow Rebol doesn't get past that question because it doesn't know the cookie was set. Instead of displaying the HTML source code of the page I entered in the text field, it shows the one of that question instead.
    
Is there a tutorial for #1 and how do I bypass the problem of #2?


posted by:   Fred     15-Jul-2010/5:43:40-7:00



I have a script that does this .. it's on my rebsite. See the compkarori2 site. As for #2, you're going to have to show me proof of age first!

posted by:   Graham     15-Jul-2010/6:07:33-7:00



I just tested your program with a gallery on my own website, Rebol shows the following error:
    
** Script Error: imagelist has no value
** Where: grabimages
** Near: clear imagelist
if not equal?


posted by:   Fred     15-Jul-2010/6:42:21-7:00



Same error here.
There is no imagelist in source, so it should be loaded from somewhere else.

posted by:   Endo     15-Jul-2010/9:29:26-7:00



Here's some basic parse code to show how to get and use a list of image links:
    
     site: http://musiclessonz.com/ScreenShots.html
     html: read site
     image-links: copy []
     parse html [any [thru {src="} copy link to {"} (append image-links link)] to end]
     ; probe image-links
     make-dir %./downloaded-images
     change-dir %./downloaded-images
     foreach image image-links [attempt [
         print rejoin ["downloading: " image]
         write/binary (to-file last split-path to-url image) (read/binary to-url image)
     ]]
     ; list-dir
     foreach image read %. [view center-face layout [image (load image)]]
    
Of course, you'll probably need to do a lot of cleaning up. Not all image links will start with a clean "src=" and end with ". If the links are not absolute URLs, you'll have to rejoin their relative locations with a base URL. This also doesn't take into consideration images that are displayed using javascript, flash, etc., but should get you going in the right direction.

posted by:   Nick     15-Jul-2010/10:01:21-7:00



Ah .. looks like the other site is down.
    
Try this
    
>> do http://www.compkarori.com/reb/webimages.r
>> do http://www.compkarori.com/reb/imagegrabber.r


posted by:   Graham     16-Jul-2010/1:36:45-7:00



Nick, I tried to adapt your code to mine and all I get is:
    
** Script Error: parse expected input argument of type: series
** Where: func [face value][
...


posted by:   Fred     17-Jul-2010/15:55:48-7:00



Fred, if you'd like some help with the code you'll need to post it, but at first glance, it looks like you're using a GUI, and need to convert the url from a string (perhaps in a text field), to a URL type, using the "to-url" function:
    
html: read to-url site

posted by:   Nick     17-Jul-2010/19:34:19-7:00



Any data retrieved from a GUI text field using fieldname/text will always be of type string! , even if that string contains a URL (or any other type of value). Just be sure to convert it to the expected REBOL data type before using it.

posted by:   Nick     18-Jul-2010/8:40:16-7:00