Perl script for IE automation
2008-04-23 12:41
591 查看
# Here is a little script that I wrote to do some automatic URL browsing using IE
# what it does is to read proxy server and port from a text named "proxylist.txt", under the same dir,
# then test if that port is active, if it is, then set it as IE's proxy, then it fires IE and browse the url picked #randomly from an array @url; then close IE.
#
# This script runs on Winodws with activestate perl installed. Also you need to install #Win32::IEAutomation module.
#
# proxylist.txt formate should be like the following:
#145.123.202.56 3128
#234.80.225.37 8080
use Win32::IEAutomation::WinClicker;
use Win32::IEAutomation;
use strict;
use Win32::TieRegistry ( Delimiter=>"/", ArrayValues=>1 );
use Net::Ping;
my $path = "proxylist.txt";
my $ie = Win32::IEAutomation->new( visible => 1, maximize => 1);
my @url = (
"http://blog.csdn.net/bsdplus/",
"http://blog.csdn.net/bsdplus/archive/2008/04/16/2296812.aspx",
"http://alan.blogcn.com",
"http://alan0203.blogspot.com",
"http://blog.csdn.net/bsdplus/archive/2007/10/22/1836987.aspx",
"http://blog.csdn.net/bsdplus/archive/2008/04/13/2289361.aspx",
"http://blog.csdn.net/bsdplus/archive/2008/04/14/2290446.aspx",
"http://alan0203.blogspot.com/2008/04/use-proxy-authentication-with-perl.html",
"http://alan0203.blogspot.com/2007/05/pcbsd-intel.html",
"http://alan0203.blogspot.com/2007/05/fcitx-pcbsd.html",
"http://alan0203.blogspot.com/2007/05/pcbsd_08.html",
"http://alan0203.blogspot.com/2007/05/windowswinxppcbsd.html",
"http://alan0203.blogspot.com/2007/05/winxppcbsd.html",
"http://alan0203.blogspot.com/2007/05/blog-post.html"
); # end of url array
open(P_SOURCE, "<", $path)
or die "Couldn't open $path for reading: $! "; #open txt file to read proxy list;
our @proxys = <P_SOURCE>;
my $waitSeconds = 2;
my $proxy_title = "Connect to myproxy.org";
my $wait_time = 1;
&set_IE_Proxy();
# start Site navigation
my $myurl = @url[int(rand(9))]; #pick a url at random;
sleep(int(rand(120)));
$ie->gotoURL($myurl,$waitSeconds);
# uncomment the following if your proxy requires username/password and if ALREADY has them cached.
# my $clicker = Win32::IEAutomation::WinClicker->new( warnings => 1);
# $clicker->push_confirm_button_ok($proxy_title, $wait_time);
$ie->WaitforDone();
print " URL is: $myurl ";
sleep(15);
$ie->closeIE();
# close(P_SOURCE);
sub set_IE_Proxy() {
my $proxy_pick = 1 + int(rand(@proxys));
print " $proxy_pick is $proxy_pick ";
my @SvrPtCn = split(" ", $proxys[$proxy_pick]); # split line into words;
print "Proxy server pick is : $SvrPtCn[0]:$SvrPtCn[1] ";
my $server = $SvrPtCn[0];
my $port = $SvrPtCn[1];
my $enable= 1 ;
my $override= "127.0.0.1;<local>";
################################################################
# start TCP PING to see if the proxy is active on specified port
my $test = Net::Ping->new('tcp', 5);
$test->{port_num} =$port;
if (! $test->ping($server)) {
print "$server:$port isn't serving HTTP! ";
&set_IE_Proxy();#next;
} else {
print "TCP Ping test ok! Setting IE proxy to $server:$port...... ";
my $rkey=$Registry->{"CUser/Software/Microsoft/Windows/CurrentVersion/Internet Settings"};
$rkey->SetValue("ProxyServer", "$server:$port", "REG_SZ");
$rkey->SetValue("ProxyEnable",pack("L",$enable), "REG_DWORD");
$rkey->SetValue("ProxyOverride", $override, "REG_SZ");
print "IE proxy set. ";
};
}; # end of sub set_IE_proxy();
相关文章推荐
- perl script for radon secure password
- MSHTML Event DispInterfaces(For Hosting or Automation IE)
- How to generate exe for your PERL script?
- 这些年我们一起搞过的持续集成~Jenkins+Perl and Shell script
- 回发或回调参数无效。在配置中使用 或在页面中使用 启用了事件验证。出于安全目的,此功能验证回发或回调事件的参数是否来源于最初呈现这些事件的服务器控件。如果数据有效并且是预期的,则使用 ClientScriptManager.RegisterForEventValidation 方法来注册回发或回调数据以进行验证。
- 电子书下载:Pro Internet Explorer 8 & 9 Development: Developing Powerful Applications for The Next Generation of IE
- Script execution failed System.Management.Automation.PSSecurityException
- 可一键运行的editor, for Lua, Perl, Python, Ruby etc..
- Sample Script for Detecting the .NET Framework 3.0 Using Internet Explorer
- async,defer for script
- LWP(Library for WWW in Perl)的基本使用
- Hungarian notation for ActionScript 匈牙利前缀AS版
- Vim 7.4.1952 with Python/Ruby/Lua/Perl/C Syntax built for Ubuntu 16.04 x86_64
- sites for debugging script
- a color class for actionscript
- Perl package Manager配置for mysql
- Win32::IEAutomation包的认识
- Get the content of an Iframe in Javascript – crossbrowser solution for both IE and Firefox
- 20 Killer Perl Programming Tips for Beginners on UNIX / Linux OS
- AUTOMATED UI TESTER FOR ADOBE® ACTIONSCRIPT® (英语原文)