Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > seting cookies to use some links with perl

Thread Tools

seting cookies to use some links with perl

Posts: n/a
I would like to use a link "Import into textBib" wich is displayed
depending on user's preferences. I tried to set these from a script
before displaying the page but it does not work. am I missing
something obvious ?

Thanks for any help

My script below:

use LWP;
use HTML:arser;
use HTML::FormatText;
use HTML::Tree;
use HTML::Form;
# use DateTime:uration;
use HTTP::Headers;
use HTTP::Cookies;
use HTTP::Cookies::Netscape;
use strict;
use warnings;

#Get the cookies in defining the preferences pages
#save the cookies in a file
my $url="";

my $ua = LWP::UserAgent->new;
$ua->agent('Mozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv: Gecko/20071025 Firefox/');
my $c = HTTP::Cookies::Netscape->new(file=>"cookies.txt",

my $h = HTTP::Headers->new(
Accept => "text/xml,application/xml,application/xhtml+xml,text/
Host => "",
$h->server("Apache/2.0.46 (Red Hat)");
$h->user_agent("Mozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv: Gecko/20071025 Firefox/");

my $req =HTTP::Request->new(GET=>$url,$h);
# $c->add_cookie_header($req);
my $res =$ua->request($req);
# $c->add_cookie_header($req);
# print $h->as_string,"\n";
die ($res->status_line) unless ($res->is_success);

# get the form and set the preference to have the bibTex Link

my @forms = HTML::Form->parse($res->content(), $res->base());

# $forms[0]->dump();
# die;

my $box = $forms[0]->find_input("scis");
die "pas de box\n" unless $box;
# foreach my $box (@rbox){
#print $box->disable()?"inactif":"actif","\n";
my @v =$box->possible_values;
# $box->value( $v[2] );
foreach my $v (@v){print "value : $v\n";}
# $box->value(undef);
my $input = $forms[0]->find_input("scisf");
if ($input){
} else {die "pas de select\n";}

my $bt = $forms[0]->find_input("submit");


# send the form
if ($bt) {
$res = $ua->request($bt->click($forms[0]));
die ($res->status_line) unless ($res->is_success);
} else {print "bt undef\n";}
# die ($res->status_line) unless ($res->is_success);
print $res->status_line,"\n";

# get the cookie back
print $res->base,"\n\n";

$url = ",
author:fribourg&hl=en&lr=&as_ylo=2007&as_yhi=2007& as_subj=bio+chm+eng

$req =HTTP::Request->new(GET=>$url,$h);

# $ua->cookie_jar($c);
$res =$ua->request($req);
die ($res->status_line) unless ($res->is_success);
my $tree = HTML::TreeBuilder->new->parse($res->content);
my @bibtexlinks = getbibtex($tree);

foreach my $l (@bibtexlinks){
print "$l\n";


my $formatter = HTML::FormatText->new();
my $ascii = $formatter->format($tree);
print $ascii;

sub getbibtex {
my ($tree) = @_;
my @out;
my @links = $tree->look_down('_tag'=>'a', 'class'=>'fl');
foreach my $a (@links){
push @out, $a->attr('href');
# push @out, $a->attr('href');
# $tree->delete;
return @out;

Script end

The ouput gives for the form (and the relevant prefs seem correct)

GET [prefform]
nosubmit=<UNDEF> (image)
submit=Save Preferences (submit)
inststart=0 (hidden readonly)
hl=en (option) [...]
lang=all (radio) [*all|some]
lr=<UNDEF> (checkbox) [*<UNDEF>/...]
lr=<UNDEF> (checkbox) [*<UNDEF>/...]
lr=<UNDEF> (checkbox) [*<UNDEF>/...]
lr=<UNDEF> (checkbox) [*<UNDEF>/...]
lr=<UNDEF> (checkbox) [*<UNDEF>/...]
lr=<UNDEF> (checkbox) [*<UNDEF>/...]
lr=<UNDEF> (checkbox) [*<UNDEF>/...]
lr=<UNDEF> (checkbox) [*<UNDEF>/...]
instq= (text)
instfind=Find Library (submit)
num=10 (option) [*10|20|30|50|100]
newwindow=<UNDEF> (checkbox) [*<UNDEF>/off|1/ ...]
scis=yes (radio) [:no|*yes]
scisf=4 (option) [*4/BibTeX|3/EndNote|2/
submit=Save Preferences (submit)

the status is ok
200 OK
the base url also

but the requested link is not display:


Dump of the result page:

Scholar Home


Advanced Scholar Search
Scholar Preferences
Scholar Help

Search only in:

Biology, Life Sciences, and Environmental Science
Chemistry and Materials Science
Engineering, Computer Science, and Mathematics
Medicine, Pharmacology, and Veterinary Science
Physics, Astronomy, and Planetary Science

Search in all subject areas.

Scholar All articles - Recent articles

Results 1 - 1 of about 290 for "fribourg, switzerland"
-author:fribourg. (0.08 seconds)

All Results

A Dulloo

J Montani

A Felikson

P Lavenex

U Albrecht

Predicting adaptive evolution under elevated atmospheric CO2 in the
perennial grass Bromus erectus
T STEINGER, A STEPHAN, B SCHMID - Global Change Biology, 2007 -
... 1 Present Address: D├®partement de Biologie, Unit├® Ecologie &
Evolution, Universit├®
de Fribourg, Chemin du Mus├®e 10, CH-1700 Fribourg,
Switzerland. ...
Cited by 1 - Related Articles - Web Search

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Give Request.Cookies and Response.Cookies is there any reason to use another method to use cookies? _Who ASP .Net 7 09-18-2008 07:49 PM
Help on seting project path =?Utf-8?B?c2VyZ2UgY2FsZGVyYXJh?= ASP .Net 2 09-06-2005 01:53 PM
Please Help With Seting up VoIP at Home. TIA for any input. 4x4 VOIP 3 04-30-2004 05:43 AM
seting mozilla to my default newsreader? Benjamin P. Firefox 0 04-15-2004 02:52 AM
need help seting up 250 colors lee ellis Computer Support 4 03-06-2004 07:45 PM