Perl script for IE automation


# 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();    
    

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值