#==================================================
# 本脚本来自 [url]www.66rpg.com[/url] 使用和转载请保留此信息
#==================================================
class Get_Http_Info
AGENT = "RGSS PLAYER"
INTERNET_OPEN_TYPE_PRECONFIG = 0 # IEの設定を仕様
INTERNET_OPEN_TYPE_DIRECT = 1 # プロキシを使用しない
def Get_Http_Info.InternetOpen()
io = Win32API.new('wininet', 'InternetOpen', %(p, l, p, p, l), 'l')
hInternet = io.call(AGENT, INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0)
return hInternet
end
def Get_Http_Info.InternetOpenUrl(hSession, url)
iou = Win32API.new('wininet', 'InternetOpenUrl', %(l, p, p, l, l, l), 'l')
hService = iou.call(hSession, url, nil, 0, 0, 0)
return hService
end
def Get_Http_Info.InternetReadFile(hService,length,bk)
content = ""
read_size = 1024 # 一次读入文件的尺寸
irf = Win32API.new('wininet', 'InternetReadFile', %(l, p, i, p), 'i')
bk.call(0,length)
id=0
while(true)
buf = "\0" * read_size
red = [0].pack('L')
irf.call( hService, buf, read_size, red )
bk.call(id*read_size,length)
id+=1
# 读到文件末端
break if (red.unpack('L') == [0])
buf.delete!("\0")
content += buf
end
return content
end
HTTP_QUERY_STATUS_CODE = 19
CONTENT_LENGTH=5
def Get_Http_Info.HttpQueryInfo(hService)
read_size = 1024
buf = "\0" * read_size
red = [read_size-1].pack('L')
hqi = Win32API.new('wininet', 'HttpQueryInfo', %(l, l, p, p, p), 'i')
isOk = hqi.call( hService, HTTP_QUERY_STATUS_CODE, buf, red, nil)
buf.delete!("\0")
return buf
end
def Get_Http_Info.InternetCloseHandle(hInternet)
ich = Win32API.new('winInet', 'InternetCloseHandle', %(l), 'i')
isOk = ich.call(hInternet)
return isOk
end
HTTP_CODE_OK = "200"
def Get_Http_Info.HttpQuerySize(hService)
read_size = 1024
buf = "\0" * read_size
red = [read_size-1].pack('L')
hqi = Win32API.new('wininet', 'HttpQueryInfo', %(l, l, p, p, p), 'i')
isOk = hqi.call( hService, CONTENT_LENGTH, buf, red, nil)
buf.delete!("\0")
return buf
end
def Get_Http_Info.get_info(url)
info = nil
begin
hInternet = InternetOpen()
if (hInternet != 0)
hService = InternetOpenUrl(hInternet, url)
if (hService != 0)
status_code = HttpQueryInfo(hService)
if (status_code == HTTP_CODE_OK)
info = InternetReadFile(hService)
end
InternetCloseHandle(hService)
end
InternetCloseHandle(hInternet)
end
rescue
# 例外发生
return nil
end
ary = []
info.each_line do |line|
next if line.empty?
ary.push line
end
return ary[271].scan(/\w+<\/a>/)
end
def Get_Http_Info.get_html(url,bk)
info = nil
# begin
hInternet = InternetOpen()
if (hInternet != 0)
hService = InternetOpenUrl(hInternet, url)
if (hService != 0)
status_code = HttpQueryInfo(hService)
length=HttpQuerySize(hService).to_i
if (status_code == HTTP_CODE_OK)
#a=File.open(pathname,"wb")
info = InternetReadFile(hService,length,bk)
end
InternetCloseHandle(hService)
end
InternetCloseHandle(hInternet)
end
#rescue
# 例外发生
# return nil
#end
return info
end
end