By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,245 Members | 1,158 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,245 IT Pros & Developers. It's quick & easy.

Mechanize module

P: 4
Hi,

i am new to perl...

i tried this module mechanize. this is the script
Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2.  
  3. # Include the WWW::Mechanize module
  4. use WWW::Mechanize;
  5.  
  6. # What URL shall we retrieve? [I HAVE TRIED DIFFERENT URLS ALSO]
  7. $url = "http://www.example.com/bestselling.html";
  8.  
  9.  
  10. # Create a new instance of WWW::Mechanize
  11. # enabling autoheck checks each request to ensure it was successful,
  12. # producing an error if not.
  13. my $mechanize = WWW::Mechanize->new(autocheck => 1);
  14.  
  15. # Retrieve the page
  16. $mechanize->get($url);
  17.  
  18. # Assign the page content to $page
  19. my $page = $mechanize->content;
  20.  
  21. # Output the page
  22. print $page;
  23.  
  24. # Let's also save the page locally
  25. open(FH, ">bestsellers.txt");
  26.  
  27. print FH $page;
  28.  
  29. close(FH);
  30.  
the error is
================================================== ==============


Error GETing http://www.example.com/bestselling.html: Can't connect to www.example.com:80 (Bad hostname 'www.example.com').

SOLUTION TRIED FROM USER GROUPS
================================================== ==============

1) i have turned off firewall with /etc/init.d/iptables stop

2) i have checked the error log file
[Wed Feb 06 10:00:09 2008] [notice] core dump file size limit raised to 18446744073709551615 bytes
[Wed Feb 06 10:00:10 2008] [notice] Digest: generating secret for digest authentication ...
[Wed Feb 06 10:00:10 2008] [notice] Digest: done
[Wed Feb 06 10:00:11 2008] [notice] Apache/2.0.46 (Red Hat) configured -- resuming normal operations


================================================== ================

BUT STILL I DONT KNOW HOW TO RECTIFY


I HAVE TRIED LWP::Simple module also but this is showing error 500.


give me some suggestion to rectifiy this


Suresh
Feb 7 '08 #1
Share this Question
Share on Google+
6 Replies


debasisdas
Expert 5K+
P: 8,127
Question move to PERL forum.
Feb 7 '08 #2

eWish
Expert 100+
P: 971
Your code works. Below is a slightly revised version.
Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl -T
  2.  
  3. use strict;
  4. use warnings;
  5.  
  6. use CGI;
  7. use CGI::Carp qw/fatalsToBrowser/;
  8.  
  9. my $q = CGI->new;
  10.  
  11. print $q->header();
  12. print $q->start_html();
  13.  
  14. # Include the WWW::Mechanize module
  15. use WWW::Mechanize;
  16.  
  17. # What URL shall we retrieve? [I HAVE TRIED DIFFERENT URLS ALSO]
  18. my $url = 'http://somesite.com';
  19.  
  20.  
  21. # Create a new instance of WWW::Mechanize
  22. # enabling autoheck checks each request to ensure it was successful,
  23. # producing an error if not.
  24. my $mechanize = WWW::Mechanize->new(autocheck => 1);
  25.  
  26. # Retrieve the page
  27. $mechanize->get($url);
  28.  
  29. # Assign the page content to $page
  30. my $page = $mechanize->content();
  31.  
  32. # Output the page
  33. print $page;
  34.  
  35. # Let's also save the page locally
  36. open(my $FH, '>', 'path/to/file/bestsellers.txt') || die "Can't open file $!\n";
  37.  
  38. print $FH $page;
  39.  
  40. close($FH);
  41.  
  42. print $q->end_html();
  43.  
  44. 1;
--Kevin
Feb 9 '08 #3

numberwhun
Expert Mod 2.5K+
P: 3,503
Well, if the code works, then I would check to ensure that there isn't a firewall in the way, stopping you from getting out.

Regards,

Jeff
Feb 9 '08 #4

KevinADC
Expert 2.5K+
P: 4,059
Well, if the code works, then I would check to ensure that there isn't a firewall in the way, stopping you from getting out.

Regards,

Jeff

Evidently he tried that already

SOLUTION TRIED FROM USER GROUPS
================================================== ==============

1) i have turned off firewall with /etc/init.d/iptables stop
Feb 9 '08 #5

numberwhun
Expert Mod 2.5K+
P: 3,503
Evidently he tried that already
he he, missed that one in my tired, zen state. Thanks!
Feb 9 '08 #6

P: 4
Hi,

Thanks for replies. The script is working now. My system admin has changed my system primary DNS server address. Now its working. Once again thanks for your prompt replies.


with regards
Suresh
Feb 12 '08 #7

Post your reply

Sign in to post your reply or Sign up for a free account.