How can I take screenshots of webpages with Perl?

后端 未结 5 1947
梦谈多话
梦谈多话 2020-12-01 05:04

Is it possible to write a script in Perl that opens different URLs and saves a screenshot of each of them?

5条回答
  •  北海茫月
    2020-12-01 05:35

    Use the WWW::Selenium module, for which you'll need to have a Selenium Remote Control session up and running.

    The capture_entire_page_screenshot() method should get you up and running.

    From WWW::Selenium on CPAN:

    $sel->capture_entire_page_screenshot($filename, $kwargs)

    Saves the entire contents of the current window canvas to a PNG file...


    A typical script:

    use strict;
    use warnings;
    use WWW::Selenium;
    
    my $sel = WWW::Selenium->new( host => "localhost", 
                                  port => 4444, 
                                  browser => "*iexplore", 
                                  browser_url => "http://www.google.com",
                                );
    
    $sel->start;
    $sel->open("http://www.google.com");
    $sel->capture_entire_page_screenshot("screenshot.png");
    $sel->close;
    

提交回复
热议问题