comet85 has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I have a simple program which connects to a website, extracts all the titles present in the source of the page and puts it in a text file. Problem is that I am behind a proxy in college and it wont work there. The program is unable to connect to the website. Upon searching for the solution I found out that I can use the LWP::Simple module. I used it and made the environment variable also. But still its not able to connect. Below is the code. Please tell me where am I going wrong and if there is any altervative to the proxy problem other than using LWP::Simple. Thanks
#!/usr/bin/perl # Include the WWW::Mechanize module use WWW::Mechanize; use LWP::Simple; # What URL shall we retrieve? $url = "http://www.rediff.com/rss/inrss.xml"; # Create a new instance of WWW::Mechanize my $mechanize = WWW::Mechanize->new(autocheck => 1); # Retrieve the page $mechanize->get($url); my $title =$mechanize->title; print "$title"; # Place all of the titles in an array my @title = $mechanize->title; open(FH, ">rediff.txt"); # Loop through and output each title foreach my $title (@title) { # Retrieve the link URL # my $href = $link->url; print FH $title; print FH "\n"; } close(FH);
Thanks in advance!

Replies are listed 'Best First'.
Re: Program wont connect as soon as I go behind a Proxy!
by atcroft (Abbot) on Mar 22, 2006 at 22:57 UTC

    A quick look at the documents included with WWW::Mechanize found WWW::Mechanize::FAQ, which, in a section entitled "How do I do X?", included the question, "How do I use WWW::Mechanize through a proxy server?", the answer to which involves setting a value for the proxy() method it inherits from LWP::UserAgent.

    Hope that helps.

Re: Program wont connect as soon as I go behind a Proxy!
by chargrill (Parson) on Mar 23, 2006 at 03:14 UTC

    While atcroft is correct about WWW:Mechanize->proxy, if memory serves WWW:Mechanize will honor $ENV{http_proxy} if set in your shell (like ->proxy, also inherited from LWP::Simple). And I believe merlyn recently pointed out in Re^4: using proxy servers with lwp::simple or useragent that it only honors the environment variable the first time it's used.

    But apologies, because I have to ask, why was consulting the documentation (a natural first step) or performing a search here so difficult?



    --chargrill
    $,=42;for(34,0,-3,9,-11,11,-17,7,-5){$*.=pack'c'=>$,+=$_}for(reverse s +plit//=>$* ){$%++?$ %%2?push@C,$_,$":push@c,$_,$":(push@C,$_,$")&&push@c,$"}$C[$# +C]=$/;($#C >$#c)?($ c=\@C)&&($ C=\@c):($ c=\@c)&&($C=\@C);$%=$|;for(@$c){print$_^ +$$C[$%++]}