ONLY DO WHAT ONLY YOU CAN DO

こけたら立ちなはれ 立ったら歩きなはれ

さまざまな言語で Internet Explorer オートメーション

VBScript

Option Explicit
 
'IE起動
Dim ie: Set ie  = CreateObject("InternetExplorer.Application")
ie.Visible      = True
ie.Toolbar      = True
ie.MenuBar      = True
ie.AddressBar   = True
ie.StatusBar    = True
 
'ログオン画面
ie.Navigate "http://192.168.1.1/zzzz.asp"
Do While ie.Busy Or ie.readystate <> 4
    WScript.Sleep 1000
Loop
 
'ユーザID
ie.Document.getElementById("txtUserID").Value = "xxxxx"
'パスワード
ie.Document.getElementById("txtPassWD").Value = "yyyyy"
'ログオン
ie.Document.forms(0).submit()

JScript

var ie          = WScript.CreateObject("InternetExplorer.Application");
ie.Visible      = true;
ie.Toolbar      = true;
ie.MenuBar      = true;
ie.AddressBar   = true;
ie.StatusBar    = true;
 
//ログオン画面
ie.Navigate("http://192.168.1.1/zzzz.asp");
while (ie.Busy || ie.readystate != 4)
    WScript.Sleep(1000);
 
//ユーザID
ie.document.getElementById("txtUserID").value = "xxxxx";
//パスワード
ie.document.getElementById("txtPassWD").value = "yyyyy";
//ログオン
ie.document.forms(0).submit();

Perl

use strict;
use warnings;
use Win32::OLE;
 
my $ie = Win32::OLE->new('InternetExplorer.Application');
 
$ie->{Visible}      = 1;
$ie->{ToolBar}      = 1;
$ie->{MenuBar}      = 1;
$ie->{AddressBar}   = 1;
$ie->{StatusBar}    = 1;
 
#ログオン画面
$ie->Navigate('http://192.168.1.1/zzzz.asp');
while($ie->Busy() || $ie->ReadyState() != 4)
{
    sleep(1);
}
 
#ユーザID
$ie->Document->getElementById("txtUserID")->{Value} = "xxxxx";
#パスワード
$ie->Document->getElementById("txtPassWD")->{Value} = "yyyyy";
#ログオン
$ie->Document->forms(0)->submit();

PHP

<?php
$ie = new COM('InternetExplorer.Application');
 
$ie->Visible    = true;
$ie->ToolBar    = true;
$ie->MenuBar    = true;
$ie->AddressBar = true;
$ie->StatusBar  = true;
 
#ログオン画面
$ie->Navigate('http://192.168.1.1/zzzz.asp');
while($ie->Busy() || $ie->ReadyState() != 4)
{
    sleep(1);
}
 
#ユーザID
$ie->Document->getElementById("txtUserID")->Value = "xxxxx";
#パスワード
$ie->Document->getElementById("txtPassWD")->Value = "yyyyy";
#ログオン
$ie->Document->forms(0)->submit();
?>

Python

# coding: Shift_JIS
import win32api, win32con, win32com, win32com.client, os, time, sys
 
ie              = win32com.client.Dispatch("InternetExplorer.Application") 
ie.Visible      = True
ie.ToolBar      = True
ie.MenuBar      = True
ie.AddressBar   = True
ie.StatusBar    = True
 
#ログオン画面
ie.Navigate('http://192.168.1.1/zzzz.asp')
while (ie.Busy and ie.ReadyState != 4):
    time.sleep(1)
 
#ユーザID
ie.Document.getElementById("txtUserID").Value = "xxxxx"
#パスワード
ie.Document.getElementById("txtPassWD").Value = "yyyyy"
#ログオン
ie.Document.forms(0).submit()

Ruby

require 'win32ole'
 
ie              = WIN32OLE.new('InternetExplorer.Application')
ie.Visible      = true
ie.Toolbar      = true
ie.MenuBar      = true
ie.AddressBar   = true
ie.StatusBar    = true
 
#ログオン画面
ie.Navigate 'http://192.168.1.1/zzzz.asp'
while (ie.Busy || ie.readystate != 4)
    sleep 1
end
 
#ユーザID
ie.Document.getElementById("txtUserID").Value = "xxxxx"
#パスワード
ie.Document.getElementById("txtPassWD").Value = "yyyyy"
#ログオン
ie.Document.forms(0).submit()

PowerShell

$ie              = New-Object -ComObject internetexplorer.application
$ie.Visible      = $true
$ie.Toolbar      = $true
$ie.MenuBar      = $true
$ie.AddressBar   = $true
$ie.StatusBar    = $true
 
#ログオン画面
$ie.Navigate('http://192.168.1.1/zzzz.asp')
while($ie.busy -or $ie.readystate -ne 4)
{
    Start-Sleep 1
}
 
#ユーザID
$ie.document.getElementById("txtUserID").Value = "xxxxx"
#パスワード
$ie.document.getElementById("txtPassWD").Value = "yyyyy"
#ログオン
@($ie.Document.forms)[0].submit()