REBOL を商用アプリケーションに何年も使用してきましたが、そのほとんどはネットワーキングを必要としますが、さまざまな方法で、REBOL のネットワーキングはかなり安定していると断言できます。実際、メモリ リークのない数か月のアップタイムを持つサーバーを作成できます。
しかし、あなたは非常に具体的な目標を念頭に置いているので、それをどのように実行して機能させるかを示す小さなアプリを作成すると思いました.
これは間違いなくR2で機能します。発生している可能性のある問題の 1 つは、ネットワーク ポートのタイムアウトですが、ダウンロードするサーバーやイメージにそれぞれ数秒かかり、デフォルトの 30 秒のタイムアウトよりも長くかかる場合にのみ発生します。
以下のアプリは、単一の URL をパラメーターとして使用し (上部付近で好きなように設定できます) 、ページで見つけたすべての<IMG> URL をダウンロードします。http と https をサポートしており、wikipedia、bing、Google 画像検索などのいくつかのサイトでテストしましたが、かなりうまく機能しています...ダウンロード速度は各サーバーでかなり一定です。ダウンロード速度を把握できるように、最小限の GUI に速度レポートを追加しました。
これは同期アプリケーションであり、画像のリストをダウンロードするだけであることに注意してください...単純にGUIを追加して同時に実行することは期待できません。これには、より複雑なネットワークを必要とする完全に異なるネットワークモデル(非同期httpポート)が必要なためです。コード。
rebol [
title: "webpage images downloader example"
notes: "works with R2 only"
]
; the last page-url is the one to be used... feel free to change this
page-url: http://en.wikipedia.org/wiki/Dog
page-url: https://www.google.com/search?q=dogs&tbm=isch
page-url: http://www.bing.com/images/search?q=dogs&go=&qs=ds
;------
; automatically setup URL-based information
page-dir: copy/part page-url find/last/tail page-url "/"
page-host: copy/part page-url find/tail at page-url 8 "/"
?? page-url
?? page-dir
?? page-host
output-dir: %downloaded-images/ ; save images in a subdir of current-directory
unless exists? output-dir [make-dir output-dir ]
images: []
;------
; read url (expecting an HTML document)
;
; Parse is used to collect and cleanup URLs, make them absolute URLs.
parse/all read page-url [
some [
thru {<img } thru {src="} copy image to {"} (
case [
"https://" = copy/part image 8 [image: to-url image]
"http://" = copy/part image 7 [image: to-url image]
"//" = copy/part image 2 [image: join http:// at image 3 ]
#"/" = pick image 1 [image: join page-host image ]
'default [image: join page-dir image]
]
append images image
)
]
]
;------
; pretty-print image list
new-line/all images yes
probe images
;------
; display report window
view/new layout [ field-info: text 500 para [wrap?: false] speed-info: text 500 ]
;------
; download images and report all activity
i: bytes: 0
s: now/precise
foreach image images [
unless attempt [
i: i + 1
probe image
legal-chars: charset [#"a" - #"z" #"A" - #"Z" "0123456789-_.="]
fname: to-string find/last/tail image "/" ; get filename from url
parse/all fname [some [ legal-chars | letter: skip (change letter "-") ] ] ; convert illegal filename chars
fname: join output-dir to-file fname ; use url filename to build disk path
write/binary fname read/binary image ; download file
; update GUI
t: difference now/precise s
field-info/text: rejoin ["Downloading: (" i "/" length? images ") " fname]
show field-info
bytes: bytes + size? fname
speed-info/text: rejoin ["bytes: " bytes ", time: " t ", speed : " (bytes / 1000) / ( to-decimal t) "kb/s"]
show speed-info
true ; all is good, attempt should return a value
][
print "^/^/---^/unable to download image:"
print image
print "---^/^/"
]
]
Web ページ スキャナーを必要とせず、取得する画像の手動リストがある場合は、そのコードを次のように画像のブロックに置き換えるだけです。
images: [
http://server.com/img1.png
http://server.com/img2.png
http://server.com/img3.png
]
ダウンロードループに任せてください。
お役に立てれば