首页 文章

一个自动脚本,它持续按下网站中的按钮

提问于
浏览
-1

在我的课程中有限的插槽,我错过了插槽,因为他们在我缺少的一天中打开了几分钟 .

因此,我计划编写一个自动脚本,该脚本会定期按下网站中的按钮 . 但我不知道从哪里开始 . 哪种语言提供了处理网页的最佳库和接口?任何指针都会有所帮助 .

一旦我编写脚本代码,我可以在哪里运行它,以便它可以在一天中定期连续执行?

1 回答

  • 1

    看看perl的WWW::Mechanize

    脚本可能如下所示:

    #!/usr/bin/perl
    
    use strict;
    use warnings;
    use WWW::Mechanize;
    my $mech = WWW::Mechanize->new();
    my $uri = "http://www.example.com"
    $mech->get( $uri ); # whatever the url of your site is
    
    while( $uri eq $mech->uri ){ 
       # you could also use while(1) to keep going indefinitely
       # I assume you end up on another site once the click was a success
    
       $mech->click_button({ name => "enter" });
       # there are other ways to find the button, worst case by number 
       # (e.g. 4th button on site ), the documentation is pretty good
    
       # $mech->back(); #perhaps, if clicking the button at the wrong time 
    
       sleep(60); #wait a minute...
    }
    

    在哪里运行它,我不知道,抱歉;) .

相关问题