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!
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.