Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7700727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:48:26+00:00 2026-05-31T22:48:26+00:00

well i run this script , which is written to do some screenshots of

  • 0

well i run this script , which is written to do some screenshots of websites
i have also up and running mozrepl

here we have the file with some of the requested urls … note this is only a short snippet of the real list – the real list is much much longer. it contains more than 3500 lines and URLs

http://www.unifr.ch/sfm
http://www.zug.phz.ch
http://www.schwyz.phz.ch
http://www.luzern.phz.ch
http://www.schwyz.phz.ch
http://www.phvs.ch
http://www.phtg.ch
http://www.phsg.ch
http://www.phsh.ch
http://www.phr.ch
http://www.hepfr.ch/
http://www.phbern.ch
http://www.ph-solothurn.ch
http://www.pfh-gr.ch
http://www.ma-shp.luzern.phz.ch
http://www.heilpaedagogik.phbern.ch/

whats strange is the output – see below…
question: should i do change the script

why do i ge the output with the following little script:

#!/usr/bin/perl

use strict;
use warnings;
use WWW::Mechanize::Firefox;

my $mech = new WWW::Mechanize::Firefox();

open(INPUT, "<urls.txt") or die $!;

while (<INPUT>) {
        chomp;
        print "$_\n";
        $mech->get($_);
        my $png = $mech->content_as_png();
        my $name = "$_";
        $name =~s/^www\.//;
        $name .= ".png";
        open(OUTPUT, ">$name");
        print OUTPUT $png;
        sleep (5);
}

see here the well overwhelming output – to be frank i never have thught to get such a funny output .. i have to debug the whole code…. see below,

http://www.unifr.ch/sfm
print() on closed filehandle OUTPUT at test_3.pl line 20, <INPUT> line 2.
http://www.zug.phz.ch
print() on closed filehandle OUTPUT at test_3.pl line 20, <INPUT> line 3.
http://www.schwyz.phz.ch
print() on closed filehandle OUTPUT at test_3.pl line 20, <INPUT> line 4.
http://www.luzern.phz.ch
print() on closed filehandle OUTPUT at test_3.pl line 20, <INPUT> line 5.
http://www.schwyz.phz.ch
print() on closed filehandle OUTPUT at test_3.pl line 20, <INPUT> line 6.
http://www.phvs.ch
print() on closed filehandle OUTPUT at test_3.pl line 20, <INPUT> line 7.
http://www.phtg.ch
print() on closed filehandle OUTPUT at test_3.pl line 20, <INPUT> line 8.
http://www.phsg.ch
print() on closed filehandle OUTPUT at test_3.pl line 20, <INPUT> line 9.
http://www.phsh.ch
print() on closed filehandle OUTPUT at test_3.pl line 20, <INPUT> line 10.
http://www.phr.ch
print() on closed filehandle OUTPUT at test_3.pl line 20, <INPUT> line 11.
http://www.hepfr.ch/
print() on closed filehandle OUTPUT at test_3.pl line 20, <INPUT> line 12.
http://www.phbern.ch                                                                                                                                                                  

Some musings: well -firstly, i think this is not a very serious error – i think i have to debug it and then it will work better.
Second, i firstly thought that the script seemed “to overload the machine”?
Now i am not very sure about that: the symptoms do look strange but i guess that it is not neecessary to conclude an “overloading of the machine”

Third, well i think of certain steps that have to be taken to ensure that the problem is at all related to WWW::Mechanize::Firefox at all?
This leads me to the point to what Perl warning means and to the idea to use the diagnostics pragma to get more explanation: what do you think?

print() on unopened filehandle FH at -e line 1 (#2) (W unopened) An I/O operation was attempted on a filehandle that w +as never initialized. 

firstly – we need to do an open(), a sysopen(), or a so +cket() call, or call a constructor from the FileHandle package
besides that – alternatively, print() on closed filehandle OUTPUT also gives lots of answers that will tell us that we did not use autodie and also did not check the return value of open.
Above all i have to debug it and make sure to find where the error comes into play[/QUOTE]

But after some musings i think that it is worth to have a closer look at all test things-,
what do you think about the idea always test to make sure the file is open before using it.That means that we should also get in the habit of using the three

arg open():

open my $fh, '>', $name or die "Can't open file $name : $!";
print $fh $stuff;

well – i guess that we can or should work around this without using die(),
but we d have to manually have some method to let us know which files couldn’t be created. In our case, it looks like all of them….that are shown above…

update in choosing a good file name you mean that i need to have a file name to store the images.. Note: i want to store all of them locally. But if i have a huge list of urls then i get a huge list of output files. Therefore i need to have good file names. Can we reflect those things and needs in the programme!?

the very latest update; there seem to be some errors with mechanize…. i guess so!!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T22:48:56+00:00Added an answer on May 31, 2026 at 10:48 pm

    I you would like to print out binary data (jpg file), you have to set it explicitly.
    Second, close a filehandler if you does not need it anymore and you ‘or die’ on open.
    Third choose a good file name.

    Regards,

    http://perldoc.perl.org/functions/binmode.html

    #!/usr/bin/perl
    
    use strict;
    use warnings;
    use WWW::Mechanize::Firefox;
    
    my $mech = new WWW::Mechanize::Firefox();
    
    open(INPUT, "<urls.txt") or die $!;
    
    while (<INPUT>) {
            chomp;
            next if $_ =~ m/http/i;
            print "$_\n";
            $mech->get($_);
            my $png = $mech->content_as_png();
            my $name = "$_";
            $name =~s#http://##is;
            $name =~s#/##gis;$name =~s#\s+\z##is;$name =~s#\A\s+##is;
            $name =~s/^www\.//;
            $name .= ".png";
            open(my $out, ">",$name) or die $!;
            binmode($out);
            print $out $png;
            close($out);
            sleep (5);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

well i run this script , which is written to do some screenshots of
I have a python script which should parse a file and produce some output
Well I have this MySQL stored procedure that I wrote and if I run
Well, this is my first post here and really enjoying the site. I have
I have made this batch script which will allow the user to enter a
I have a python (2.5.4) script which I run in cygwin (in a DOS
I have several Oracle queries that perform well when run through SQL*PLUS. However when
I have written a userscript , and run it in Greasemonkey 0.9.13. If I
So I wrote a Python script which does some simple stuff. It was originally
I've written a small python script to create a file and calculate times. I've

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.