googleでは、検索文字列をUTF8でエンコードすれば、アルファベット以外もOK。
//----------------------------------------------------------------------------
#module RE
;┌─────────────────────────────
;│文字列が正規表現に一致するか調べる
;│Params:
;│ var v = 対象の文字列(変数)
;│ str pattern = 正規表現パターン
;│ str flags = 正規表現フラグ
;│Return:
;│ int 0:不一致 >0:一致(サブマッチ個数)
;│ str array subMach@RE = サブマッチ
;│ str lastMatch@RE = 最終一致文字列
;│ str leftContext@RE = 一致箇所より前の文字列
;│ str rightContext@RE = 一致箇所より後の文字列
;└
#defcfunc REMatch var _v, str _pattern, str _flags
if( vartype(ScriptControl) != 6 ) { gosub *init }
dummy = strmid(_v,0,0) //check
ScriptingDictionary->"RemoveAll"
n = ScriptControl("Run","REMatch", _v, _pattern, _flags, ScriptingDictionary )
sdim subMach,,n
lastMatch = ""
rightContext = ""
leftContext = ""
if(n) {
repeat n
subMach(cnt) = ScriptingDictionary("Item", ""+cnt)
loop
lastMatch = ScriptingDictionary("Item", "lastMatch")
rightContext = ScriptingDictionary("Item", "rightContext")
leftContext = ScriptingDictionary("Item", "leftContext")
ScriptingDictionary->"RemoveAll"
}
return n
*init
newcom ScriptControl, "ScriptControl"
if( varuse(ScriptControl) == 0 ) { dialog "ScriptControl の初期化に失敗" : stop }
ScriptControl("Language") = "JScript"
ScriptControl->"ExecuteStatement" {"
//---------------------------------------------------------------------------
function REMatch( s, pattern, flags, dic ) {
var re = new RegExp(pattern, flags);
var m = s.match(re);
if( m == null ) return 0;
for( var i = 0 ; i < m.length ; i++ ) {
dic.Add( ''+i, m[i] );
}
dic.Add( 'lastMatch', RegExp.lastMatch != null ? RegExp.lastMatch : '' );
dic.Add( 'rightContext', RegExp.rightContext != null ? RegExp.rightContext : '' );
dic.Add( 'leftContext', RegExp.leftContext != null ? RegExp.leftContext : '' );
return m.length;
}
//---------------------------------------------------------------------------
"}
newcom ScriptingDictionary, "Scripting.Dictionary"
if( varuse(ScriptingDictionary) == 0 ) { dialog "Scripting.Dictionary の初期化に失敗" : stop }
return
#global
//---------------------------------------------------------------------------
#include "winmm.as"
#include "kernel32.as"
#const CP_UTF8 $0000FDE9
sdim s, 2048
input s, 200,24
button gosub "画像検索", *Download
html = ""
mesbox html, 600,150, 5, 0 : oi_html = stat
result = ""
mesbox result, 600,150, 5, 0 : oi_result = stat
cx = ginfo_cx : cy = ginfo_cy
stop
*Download
if( busy ) { return }
if( s == "" ) { return }
busy = 1
color 255,255,255 : boxf : color
pos cx,cy
mes "start"
html = "" : objprm oi_html, html
result = "" : objprm oi_result, result
url = "http://images.google.co.jp/images?hl=ja&q="
alloc buf1, strlen(s)*2+2
cnvstow buf1, s
WideCharToMultiByte CP_UTF8, 0, varptr(buf1), -1, 0, 0, 0, 0 : len2 = stat
alloc buf2, len2
WideCharToMultiByte CP_UTF8, 0, varptr(buf1), -1, varptr(buf2), len2, 0, 0
repeat len2-1
c = peek(buf2,cnt)
if( ('a'<=c && c<='z') || ('A'<=c && c<='Z') || ('0'<=c && c<='9') || (c=='-') || (c=='_') ) {
url += strf("%c", c)
}
else {
url += strf("%%%02X", c)
}
loop
url += "&btnG=%E3%82%A4%E3%83%A1%E3%83%BC%E3%82%B8%E6%A4%9C%E7%B4%A2&gbv=1"
newcom HTTP, "MSXML2.XMLHTTP"
if( varuse(HTTP) == 0 ) { dialog "MSXML2.XMLHTTP の初期化に失敗" : stop }
HTTP->"SetRequestHeader" "If-Modified-Since", "Thu, 01 Jun 1970 00:00:00 GMT"
HTTP->"Open" "GET", url, 1
HTTP->"Send"
mes "ダウンロード中・・・"
timeGetTime
t = stat + 1000*20 //タイムアウト20秒
while( HTTP("readyState") != 4 )
wait 10
timeGetTime
if( t < stat ) { _break }
wend
if( HTTP("readyState") == 4 ) {
if( HTTP("Status") == 200 ) {
html = HTTP("responseText")
mes "ダウンロード成功"
objprm oi_html, html
}
else {
mes "ダウンロード失敗" : busy = 0 : stop
}
}
else {
mes "ダウンロード失敗" : busy = 0 : stop
}
delcom HTTP
count = 0
work = html
while( REMatch( work, "<img src=(\\S+) ", "" ) )
work = rightContext@RE
result += subMach@RE(1) + "\n"
count++
wend
objprm oi_result, result
mes "画像URL数 "+count
busy = 0
return