I am trying to download the contents of a web page. I have two parameter variables that I am trying to use in the URL:
$month = "1" $year = "2013"
The problem is that the cookie values for the URL aren't being set properly. I then use the cookie data for a follow-up HTTP request. The URL works if I don't use variables and hard-code the values for Month and Year, but it doesn't work when I use the variables Month=$month and Year=$year. The variable is $url_to_get. It works when I put the values in for Month and Year:
$url_to_get = 'http://tennislink.usta.com/Tournaments/Schedule/SearchR +esults.aspx?Action=2&Month=1&Year=2013&Sanctioned=0&SearchRadius=-1&E +ntryLevel=False&Intermediate=False&Advanced=False';
but this doesn't work:
$url_to_get = 'http://tennislink.usta.com/Tournaments/Schedule/SearchR +esults.aspx?Action=2&Month=$month&Year=$year&Sanctioned=0&SearchRadiu +s=-1&EntryLevel=False&Intermediate=False&Advanced=False';
This is a portion of my script: (some of the modules are for other parts of the script)
#!/usr/bin/perl use URI::URL; use LWP::UserAgent; use HTTP::Request; use HTTP::Headers; use HTTP::Response; use HTTP::Cookies; use WWW::Mechanize; $month = "3"; $year = "2014"; $url_to_get = 'http://tennislink.usta.com/Tournaments/Schedule/SearchR +esults.aspx?Action=2&Month=$month&Year=$year&Sanctioned=0&SearchRadiu +s=-1&EntryLevel=False&Intermediate=False&Advanced=False'; $ua = LWP::UserAgent->new; $ua->agent('Mozilla/4.0 (Compatable; MSIE 5.01; Windows NT 5.0)'); $ua->cookie_jar(HTTP::Cookies->new(file => "lwpcookies.txt", autosave +=> 1)); $res = $ua->request(HTTP::Request->new(GET => "$url_to_get")); $content = $res->as_string( ); @content = split ("\n", $content); foreach $info (@content) { if ($info =~ "Displaying 1 ") { print "$info\n"; } }
This is what gets written to the cookie file:
cat lwp* #LWP-Cookies-1.0 Set-Cookie3: BigIPCookie=3658774282.20480.0000; path="/"; domain=tenni +slink.usta.com; path_spec; expires="2013-12-12 23:07:09Z"; version=0 Set-Cookie3: tennislink.usta.com_Search="Action=2&Keyword=&TournamentI +D=&SectionDistrict=&City=&State=&Zip=&Month=0&Day=&Year=0&Division=&C +ategory=&Surface=&OnlineEntry=0&DrawsSheets=0&PageNum=0&UserTime=&San +ctioned=0&AgeGroup=&SkillLevel_EntryLevel=False&SkillLevel_Intermedia +te=False&SkillLevel_Advanced=False&SearchRadius=-1&QuickSearch=0&Orde +rBy=3"; path="/"; domain=tennislink.usta.com; path_spec; expires="201 +4-06-12 18:07:08Z"; version=0
You can see that the Month and Year values in the tennislink.usta.com cookie are set to zero. (The values for $month and $year are normally entered on the command line).

Any assistance will be greatly appreciated.


In reply to HTTP::Request -Variable values not translating in URL by Tonyd5915

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.